What event is fired when Laravel app is being shutdown?

前端 未结 2 1446
失恋的感觉
失恋的感觉 2021-01-21 20:15

Specifically what I am doing is in my AppServiceProvider->boot() method I am creating a singleton class like below:

class AppServiceProvider extends ServiceProvi         


        
2条回答
  •  无人共我
    2021-01-21 20:58

    You can use the boot method for anything. From laravel docs:

    This method is called after all other service providers have been registered, meaning you have access to all other services that have been registered by the framework

    The key is that boot method run when all services are registered, so, you can inject services in the boot method definition.

    public function boot(SomeService $someService, OtherService $otherService)
    {
        $someService->doSomething();
        $otherService->doSomething();
    }
    

    In my opinion, you must to use this method to run code required by your app in all contexts: user logged in, user logged out, post, get, put, etc., etc.

提交回复
热议问题