F
Filamentβ€’15mo ago
ngaiza_287

Get Relationship Value in Table Action from Form

Hello, Am trying to get a value of a relationship field in table action from action form. I cant seem to get it of $data array. Action::make('add') ->label('Add Results') ->icon('heroicon-s-plus-circle') ->color('warning') ->form([ Select::make('exam_id') ->label('Examination') ->options(Exam::all()->pluck('name', 'id')) ->required(), Select::make('subject_id') ->label('Subject') ->relationship('subjects', 'name') ->hint('Please select only one subject') ->multiple() ->required() ->preload(), ])->action(function (Model $record, array $data): string { $subject = $data['subject_id']; // I need to get this value dd($subject); return redirect()->route('results.record', [ 'grade' => $record, 'exam' => $data['exam_id'], 'subject' => $data['subject_id'] ]); }),
4 Replies
Dennis Koch
Dennis Kochβ€’15mo ago
Use ->options() instead of ->relationship() because that also affects how the field is dehydrated.
Dan Harrin
Dan Harrinβ€’15mo ago
or just use ->dehydrated() on that select
Dennis Koch
Dennis Kochβ€’15mo ago
I knew there was another one, but thought it needed more configuration πŸ˜…
ngaiza_287
ngaiza_287β€’15mo ago
Thank you lots!