Reputation: 3347
How can I create a policy/gate to restrict users from accessing Nova tools (e.g. Spatie Nova Backup Tool)?
Upvotes: 2
Views: 2618
Reputation: 3293
Doing this the "Nova way", would be using the canSee()
-method. You can read about it here.
public function tools()
{
return [
YourToolThatMightBeHidden::make()
->canSee(function ($request) {
return $request->user()->can('access-this-tool');
}),
];
}
Upvotes: 5
Reputation: 4849
I had the same issue and I resolved it like this.
NovaServiceProvider
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.
Upvotes: 1