Search code examples
laravelauthorizationpolicylaravel-nova

How to create a Laravel Nova Gate/Policy to restrict access to Nova tools?


How can I create a policy/gate to restrict users from accessing Nova tools (e.g. Spatie Nova Backup Tool)?


Solution

  • I had the same issue and I resolved it like this.

    1. Go to NovaServiceProvider
    2. Add a gate/check in the tools() method

      public function tools()
      
      {
      
          if (Auth::user()->hasAnyRole(['admin'])) {
              return [new Foo, new Bar];
          }
      
          return [];
      }
      

    This will solve the issue but I am not sure wether this is the Nova way of doing it or not.