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)),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server