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
Use
->options()
instead of ->relationship()
because that also affects how the field is dehydrated.or just use
->dehydrated()
on that selectI knew there was another one, but thought it needed more configuration π
Thank you lots!