© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
Demon-CZ

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
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)**
                    ])
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();
    }
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');
    }
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');
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

attach form
FilamentFFilament / ❓┊help
3y ago
Form Attach action?
FilamentFFilament / ❓┊help
2y ago
Attach Option Form...?
FilamentFFilament / ❓┊help
3y ago
format options on relationship manager select in attach form
FilamentFFilament / ❓┊help
3y ago