c-monster
c-monster
FFilament
Created by c-monster on 2/29/2024 in #❓┊help
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)),
1 replies
FFilament
Created by c-monster on 1/18/2024 in #❓┊help
Import date field error
No description
5 replies
FFilament
Created by c-monster on 1/16/2024 in #❓┊help
Select->relationship order
I've just found Filament and am loving it! Is it possible to specify a sort order when displaying a select with a relationship? Rather than have the options in alpha order by name?
Select::make('category')
-> relationship('category','name')->orderby('category.id', 'DESC'),
Select::make('category')
-> relationship('category','name')->orderby('category.id', 'DESC'),
Thanks, c-monster
4 replies