Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

elo's avatar
Level 3

Assigning Roles on Nova dashboard using Spatie Laravel-Permissions Package

I am currently using spatie laravel permissions package in a laravel 5.8 project and using Nova for admin.

I want the super admin user to be able to assign a role to selected users from the nova dashboard. This is how I have attempted to do it, by using nova actions. I created a GrantAdminRole action and doing the role assingment inside the handle method like this

public function handle(ActionFields $fields, Collection $models)
{
    foreach ($models as $model) {

        // grant user admin role
        $model->assignRole(['admin']);
    }

    return Action::message('User has been assigned Admin role.');
}

Then in my app\Nova\User action method I am using the GrantAdminRole action

public function actions(Request $request)
{
    return [
        (new GrantAdminRole)->canSee(function ($request) {
            return $request->user()->hasRole(['super-admin']);
        })
    ];
}

Now when I try to assign the role, I get an error message

Sorry! You are not authorized to authorized to perform this action

How can I fix this? I am thinking I need a policy but can't figure out how what the policy should look like.

0 likes
0 replies

Please or to participate in this conversation.