Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gate is overwritten by package #397

Closed
niekdemelker opened this issue Jul 21, 2024 · 1 comment
Closed

Gate is overwritten by package #397

niekdemelker opened this issue Jul 21, 2024 · 1 comment

Comments

@niekdemelker
Copy link

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.

@timacdonald
Copy link
Member

@niekdemelker, you should not be defining the gate in the booting callback. You should be doing it inline within the boot method as documented.

Screenshot 2024-07-22 at 09 28 04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants