Attaching additional information to a RelationManager?
When I add a RelationManager I want it to ask for or populate the year from a drop down - how can I add that in?
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->recordTitle(fn (Model $record): string => "{$record->student_number} - {$record->first_name} {$record->last_name} {$record->grade_level} {$record->school->name}")
->recordSelect(
fn (Select $select) => $select->placeholder('Student number or name'))
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
])
->recordSelectOptionsQuery(fn (Builder $query): Builder => $query->where('grade_level', '>',8)->orderBy('last_name'))
->recordSelectSearchColumns(['student_number','first_name','last_name']),
2 Replies
try adding
->form([Select::make('year')->options(['yeears here))
That should prompt a popup with a form, then pass $data var into the closures
Like this?
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->recordTitle(fn (Model $record): string => "{$record->student_number} - {$record->first_name} {$record->last_name} {$record->grade_level} {$record->school->name}")
->recordSelect(
fn (Select $select) => $select->placeholder('Student number or name'))
->form(fn (AttachAction $action, $data): array => [
$action->getRecordSelect(),
Select::make('school_year')->options(['2024'=>'2024','2025'=>'2025'])
])
->recordSelectOptionsQuery(fn (Builder $query): Builder => $query->where('grade_level', '>',8)->orderBy('last_name'))
->recordSelectSearchColumns(['student_number','first_name','last_name']),
])