© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
8 replies
lkucharski

Sorting Forms/Components/Select by Pivot Table Field

Maybe someone would like to help me.

1️⃣ I have a Person model that has a relationship to the Operator model
public function operator()
{
    return $this->hasOne(Operator::class);
}
public function operator()
{
    return $this->hasOne(Operator::class);
}

2️⃣ The Operator model has a relationship to the Roles model
public function roles()
{
    return $this->belongsToMany(Roles::class, 'role_operator')->withOrganisationOrShared();
}
public function roles()
{
    return $this->belongsToMany(Roles::class, 'role_operator')->withOrganisationOrShared();
}

3️⃣ I have a Select component in Form and it works fine with these relationship operator.roles.
Components\Group::make()
    ->relationship('operator')
    ->schema([
        Components\Select::make('roles')
            ->relationship(name: 'roles', titleAttribute: 'label')
            ->live()
            ->label('Przypisane role')
            ->multiple()
            ->preload()
    ])
Components\Group::make()
    ->relationship('operator')
    ->schema([
        Components\Select::make('roles')
            ->relationship(name: 'roles', titleAttribute: 'label')
            ->live()
            ->label('Przypisane role')
            ->multiple()
            ->preload()
    ])

How could he sort the returns Roles in Select by Pivot Table ID?
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

\Forms\Components\Select
FilamentFFilament / ❓┊help
5mo ago
Run Forms\Components\Select::..->options(..) after another Forms\Components\Select filled
FilamentFFilament / ❓┊help
3y ago
Filament\Forms\Components\Select::isOptionDisabled():
FilamentFFilament / ❓┊help
3y ago
enum value in Forms\Components\Select
FilamentFFilament / ❓┊help
2y ago