php - The current authentication user information obtained in __construct in laravel5.4 Controller is NULL
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-06 09:54:18
0
2
1095

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...

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
仅有的幸福

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

某草草
//现在的处理方式, 为了取个登录用户这样子写有点那啥哦...
public function __construct()
    {
        $this->middleware(function($request, $next) {
            $this->loginUser = $this->getUser();
            //$this->loginUser = $request->user();
            view()->share('loginUser', $this->loginUser);
            return $next($request);
        });
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template