Relationship Manager AttachAction custom form

Hi all, I try to attach Employee model to Training Model. In the table employee_tainings there is a required training_session_id. I would like to modify the AttachAction form to have another field so that user can select training session before submiting. However, No matter I try to change form() in configurationAttachAction(), it won't affect . Please advise how I would do this.
protected function configureAttachAction(Tables\Actions\AttachAction $action): void
{
$action
->authorize(static fn(RelationManager $livewire): bool => (! $livewire->isReadOnly()) && $livewire->canAttach())
->form(static fn(Form $form) => $form->schema([
Forms\Components\TextInput::make('full_name')
->required()
->maxLength(255),
Forms\Components\Select::make('training_session_id')
->options(
\App\Models\TrainingSession::all()->pluck('name', 'id')
)
]))
->attachAnother(false);
}
protected function configureAttachAction(Tables\Actions\AttachAction $action): void
{
$action
->authorize(static fn(RelationManager $livewire): bool => (! $livewire->isReadOnly()) && $livewire->canAttach())
->form(static fn(Form $form) => $form->schema([
Forms\Components\TextInput::make('full_name')
->required()
->maxLength(255),
Forms\Components\Select::make('training_session_id')
->options(
\App\Models\TrainingSession::all()->pluck('name', 'id')
)
]))
->attachAnother(false);
}
No description
Solution:
I just found that I could not do it from function configureAttachAction, but it works on header action extensiion itself. ```php $table->headerActions([ Tables\Actions\AttachAction::make() ->form(fn(AttachAction $action): array => [...
Jump to solution
1 Reply
Solution
Zen Nitiruj
Zen Nitiruj3mo ago
I just found that I could not do it from function configureAttachAction, but it works on header action extensiion itself.
$table->headerActions([
Tables\Actions\AttachAction::make()
->form(fn(AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('training_session_id')
->options(
\App\Models\TrainingSession::where('training_id', $this->getOwnerRecord()->id)->pluck('name', 'id')
)
])
->action(
function (array $arguments, array $data, Form $form, Table $table, AttachAction $action): void {
$this->doAttach($arguments, $data, $form, $table, $action);
}
)
->attachAnother(false),
])
$table->headerActions([
Tables\Actions\AttachAction::make()
->form(fn(AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('training_session_id')
->options(
\App\Models\TrainingSession::where('training_id', $this->getOwnerRecord()->id)->pluck('name', 'id')
)
])
->action(
function (array $arguments, array $data, Form $form, Table $table, AttachAction $action): void {
$this->doAttach($arguments, $data, $form, $table, $action);
}
)
->attachAnother(false),
])
Want results from more Discord servers?
Add your server