php - laravel 5.1: Auth::check return false in ServiceProvider -


i looking similar issues didn't me. auth::check return false , auth::guest return true, auth middleware work correct(lets request continue if user logged in , redirect user login page if user not logged in). whats wrong?

edit: understood occurs in provider boot method , question : how check user login status in provider boot method? provider boot method share menu in views:

 public function boot(menucontroller $menu_controller) {    //dd(\auth::check()) not work here      $nav_menu = $menu_controller::roots()->get();      view()->share('nav_menu',$menus); } 

auth::check() using session check if user autheticated.

in laravel session initialized via middleware, , all middlewares execute after service providers boot phase

so, in service provider can't access session: has not been initialized yet

the solution check authentication , work in middleware, , let middleware execute after this:

\illuminate\session\middleware\startsession::class 

that middelware starts session


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -