forked from dillingham/nova-attach-many
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
I'm currently facing the issue where I want to fix the following:
A User has multiple roles in the Resource as following:
AttachMany::make('Roles', 'roles', Role::class)->required()->rules('required'),
These Roles are Spatie/laravel-permissions roles.
On a User Edit form in Nova I want to check which roles a User can add with the following code:
`public function attachRole(User $user, User $model, Role $role): bool
{
if ($model->hasRole('admin')) {
return false;
}
if (!$user->hasRole('admin') && $role->name === 'admin') {
return false;
}
if (!$user->hasRole('admin') && $user->id === $model->id) {
return false;
}
if ($user->hasRole('content manager') || $user->hasRole('event manager')) {
return true;
}
return false;
}`
But $model is always an empty User model. i.e.
$user->id === $model->id
Equals 6 === null.
Do you use a new model, or an existing model in a edit form of a resource?
Metadata
Metadata
Assignees
Labels
No labels