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?
7 Replies
lkucharski
lkucharski6mo ago
Could anyone help me? 🙂
lkucharski
lkucharski6mo ago
I tried and it didn't work.
No description
lkucharski
lkucharski6mo ago
No description
lkucharski
lkucharski6mo ago
And it doesn't work either
lkucharski
lkucharski6mo ago
No description
lkucharski
lkucharski6mo ago
No description
Want results from more Discord servers?
Add your server
More Posts