search

Home  >  Q&A  >  body text

php - The current authentication user information obtained in __construct in laravel5.4 Controller is NULL

Because each page requires the information of the currently logged in user

So I want to get the authentication information in the parent Controller(__construct) and share it with all views!

The problem now is that neither of these two places can obtain login user information

//You won’t let me set data everywhere I need it...

曾经蜡笔没有小新曾经蜡笔没有小新2729 days ago1101

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-06 09:56:18

    Read the manual http://laravelacademy.org/pos... This feature has been changed since laravel5.3.

    reply
    0
  • 某草草

    某草草2017-06-06 09:56:18

    //现在的处理方式, 为了取个登录用户这样子写有点那啥哦...
    public function __construct()
        {
            $this->middleware(function($request, $next) {
                $this->loginUser = $this->getUser();
                //$this->loginUser = $request->user();
                view()->share('loginUser', $this->loginUser);
                return $next($request);
            });
        }

    reply
    0
  • Cancelreply