© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago
c-monster

attach action form and pivot values

I'm working on an attendance system and struggling with customising the attach action and form. There seem to be several affordances in that class, but I haven't been able to piece together how they all work.
I have the following DB schema:
cohort -hasMany()-> activity ->hasMany() - timeslot
cohort -hasMany()-> student
student-timeslot (many-many) pivot table to attach students to a timeslot - this has a pivot field to indicate (present, late, excused, absent)

I have a StudentsRelationManager on the TimeslotResource with an AttachAction.
The things I would like to do include:
* reference a different field in the attach select dropdown - I'm getting first_name and I'd like full_name
* scope the list of students available to attach to be limited to the timeslot->activity->cohort
* add another element to the attach form to set the pivot field - probably a dropdown with one of the above enumeration (p, l, e, a)

I've seen that the following might be possible, but don't know how they all fit together.
How could I implement these features?

AttachAction::make()
  ->recordSelectSearchColumns(['full_name', 'fan'])
  ->form(fn (AttachAction $action): array => [
       $action->getRecordSelect()
       ->getOptionLabelsUsing(function ($value): string {
             $student = Student::find($value);
             return static::getCleanOptionString($student);
         })
  ])
  
  // In a relationship...
  ->modifyQueryUsing: function(Builder $query){ $query->where(cohort_id, cohort_id)}
                
  ->recordSelectOptionsQuery(fn (Builder $query) => $query->                         whereBelongsTo(timeslot()->activity()->cohort)),
AttachAction::make()
  ->recordSelectSearchColumns(['full_name', 'fan'])
  ->form(fn (AttachAction $action): array => [
       $action->getRecordSelect()
       ->getOptionLabelsUsing(function ($value): string {
             $student = Student::find($value);
             return static::getCleanOptionString($student);
         })
  ])
  
  // In a relationship...
  ->modifyQueryUsing: function(Builder $query){ $query->where(cohort_id, cohort_id)}
                
  ->recordSelectOptionsQuery(fn (Builder $query) => $query->                         whereBelongsTo(timeslot()->activity()->cohort)),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Form Attach action?
FilamentFFilament / ❓┊help
2y ago
Attach Pivot attributes
FilamentFFilament / ❓┊help
2y ago
Edit resource in attach action form?
FilamentFFilament / ❓┊help
2y ago
Attach form
FilamentFFilament / ❓┊help
3y ago