Jul 27, 2024
0
Level 7
Many to Many Custom Action Select Multiple
I have a many to many relationship (schedule_student).. I created a custom action that will attach the schedule to the student..
Tables\Actions\Action::make('Assign Schedule')
->form([
Forms\Components\Select::make('students')
->relationship(
'students',
modifyQueryUsing: fn (Builder $query) => $query->orderBy('last_name')->orderBy('first_name'),
)
->getOptionLabelFromRecordUsing(fn ($record) => $record->getFullName())
->searchable()
->multiple()
->preload()
->optionsLimit(5)
->required(),
])
->modalSubmitActionLabel('Assign Schedule')
->action(function (array $data, $record) {
$record->students()->syncWithoutDetaching($data['students']);
Notification::make()
->title('Schedule assigned successfully!')
->success()
->send();
}),
When i add multiple() in my select.. $data returns a blank array..
my goal is that i should be able to assign schedule to a multiple students
Please or to participate in this conversation.