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);
}

2️⃣ The Operator model has a relationship to the Roles model
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()
    ])

How could he sort the returns Roles in Select by Pivot Table ID?
Was this page helpful?