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

agilasadi's avatar

Laravel nova access restriction vie Gate does not work

I tried to restrict access to Nova depending on user role. Although It seems like I did everything according to the documentation, Nova seems to ignore it.

    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return in_array($user->role_id, [
                '1'
            ]);
        });
    }
0 likes
8 replies
ejdelmonico's avatar

Did you test the gate in a production environment? If I remember correctly, Nova allows all in local dev environment and uses the gate in a production one.

ejdelmonico's avatar

Then, try using Tinker to see if the user model actually has the role_id attached. Pick any user with Tinker to see the returned model.

agilasadi's avatar

I did solve it but I do not remember the solution, perhaps composer dump-autoload will help

elo's avatar

Check your APP_ENV value. If it is still set to local the gate will have no effect. So you should change it to maybe staging or production as the case maybe then run php artisan config:cache. That should trigger the authorization using gate.

1 like
ERashdan's avatar

I solved the problem by turn off Laravel sail and reboot it up

Please or to participate in this conversation.