Laravel, Auth::user() in controller

后端 未结 9 1855
说谎
说谎 2021-02-20 11:44

Laravel framework- Why aren\'t I able to use Auth::user(), (to see if user has been logged in) in the controller of the laravel project. Is the Session not connected to the cont

相关标签:
9条回答
  • 2021-02-20 12:14

    Just add the following in your controller library.

    use Illuminate\Support\Facades\Auth;
    
    0 讨论(0)
  • 2021-02-20 12:19

    To see if a user is loged in don't use Auth::user(). Use Auth::check() instead.

    if (Auth::check()){
        return View::make('home.basic')->with('user', Auth::user());
    }
    
    0 讨论(0)
  • 2021-02-20 12:28

    additionally, you can also use the auth() helper without adding the facade in your controller. (i.e. auth()->user()

    0 讨论(0)
提交回复
热议问题