If you have defined the gate, you should be able to use the blade helper function
@can('viewNova')
<a href="#">Foo</a>
@endcan
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I normally use the following in Blade, to show Nova-button, if user is allowed to access:
@if(Auth::user()->email == '[email protected]')
...
How can I modify above code, to match against NovaServiceProvider file? Or is there a better way to handle it?
(I define what e-mails are allowed to access Nova, using the NovaServiceProvider file)
protected function gate()
{
Gate::define('viewNova', function ($user) {
return in_array($user->email, [
'[email protected]',
'[email protected]',
]);
});
}
I decided to test this out, as close as I could, without having nova available:
In my AppServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
/**
* Register any application services.
*
* @return void
*/
public function register() {
if ($this->app->environment('local')) {
$this->app->register(TelescopeServiceProvider::class);
}
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
Paginator::useBootstrap();
Gate::define('viewNova', function ($user) {
return in_array($user->email, [
'[email protected]',
]);
});
}
}
Then added this to a blade file:
<div class="container-fluid">
@can('viewNova')
<h1>Can view nova</h1>
@endcan
And "can view nova" appeared in the blade, as expected.
So, I can only assume that this gate is not being applied properly, or potentially Nova does not register the service provider in local environments.
Please or to participate in this conversation.