Skip to content

LARAVEL_STATIC_TO_INJECTION in AppServiceProvider breaks app after injecting dependencies in constructor #315

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

Open
gjvanahee opened this issue Mar 19, 2025 · 0 comments

Comments

@gjvanahee
Copy link

Rector proposes the following change, but there is no injection in service providers. The constructor requires an Application instance $app as it's first (and only) argument.

 class AppServiceProvider extends ServiceProvider
 {
+    public function __construct(private readonly \Illuminate\Contracts\Auth\Access\Gate $gate)
+    {
+    }

     public function boot(): void
     {
-        Gate::before(fn ($user, $ability) => $user->email === '***');
+        $this->gate->before(fn ($user, $ability) => $user->email === '***');
     }
 }
    ----------- end diff -----------

The accepted code will throw an exception:

App\Providers\AppServiceProvider::__construct(): Argument # 1 ($gate) must be of type Illuminate\Contracts\Auth\Access\Gate, Illuminate\Foundation\Application given

rector/rector: 2.0.10
driftingly/rector-laravel: 2.0.2
laravel/framework: 11.44.2

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

1 participant