Attach form
I have model of user function, user and event. I have table for user functions, users, events and pivot tables for function_user, function_event and event_instructor(instructor equals user)...In relation manager for users in events I am attaching users to event. In the attach form I have select for user but I would also like to have select for his roles. How can this be achieved? I have tried to add here parts of code but if you need more information about some parts just tell me. Thank you for your help.
InstructorsRelationManager on event
Event model
UserFunction Model
InstructorsRelationManager on event
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['title', 'description'])
->recordSelectOptionsQuery(fn(Builder $query
) => $query->selectRaw("CONCAT(jmeno,' ', prijmeni) as jmeno, id"))
->label(__('Priradit instruktora'))
->form(fn(Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
**//HERE I NEED TO ADD SELECT FOR THE USER ROLES THAT THE CURRENT USER HAS (its the user that has been selected in the previous select)**
])Event model
public function instructors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'event_instructor', 'jednorazovekurzy_id',
'uzivatele_id')->withPivot(['salary', 'salary_type', 'added_by'])->noRegularUsers()->visible();
}UserFunction Model
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'user_userfunction', 'user_id', 'userfunction_id');
}
public function events(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Event::class, 'event_userfunction', 'event_id', 'userfunction_id')->withPivot('capacity', 'current_capacity');
}