Populating select drop down with correct Spatie role value

I can display a user's associated Spatie role in a table like this:

->columns([
Tables\Columns\BadgeColumn::make('roles.name'),
])

When I want to edit the user form with a select menu, I can also display the names of the roles like this:

Select::make('role')
->required()
->relationship('role', 'name'),

The problem is, it doesn't seem to pick up the current value of the role in the select dropdown menu..
How do I get it to default to the current value?

If it was my own "roles" model, I'd add a relationship function in there, but in this case it's getting it from the Spatie role model.

I tried to add a custom model to add the relationship, but that didn't work either:

use Spatie\Permission\Models\Role;

class CustomRole extends Role
{
// Additional customizations here
public function customrole()
{
return $this->hasMany(Role::class);
}
}
Was this page helpful?