Gate is overwritten by package
niekdemelker opened this issue · 1 comments
Pulse Version
v1.2.4
Laravel Version
11.15.0
PHP Version
8.2.4
Livewire Version
v3.5.2
Database Driver & Version
No response
Description
I used the Gate::define('viewPulse', fn() => ...) to define who can see Pulse. Because I use Laravel Nova and i need to check this permission rendering the menu i define this gate in de booting state of the app service provider.
Now I noticed the gate will not work in production because it is overwritten by the Pulse Service Provider in the function registerAuthorization().
A solution is checking if the ability already exists, like in this example
protected function registerAuthorization(): void
{
$this->callAfterResolving(Gate::class, function (Gate $gate, Application $app) {
if ($gate->has('viewPulse')) {
return;
}
$gate->define('viewPulse', fn ($user = null) => $app->environment('local'));
});
}Steps To Reproduce
define the gate in the $this->app->booting(fn () => ...)); in the app service provider. It will be overwritten.
@niekdemelker, you should not be defining the gate in the booting callback. You should be doing it inline within the boot method as documented.
