Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eskiesirius's avatar

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

0 likes
0 replies

Please or to participate in this conversation.