Heim > Fragen und Antworten > Hauptteil
求助求助!laravel5.4在类的构造函数中打印Auth::check();返回的是false,在类的方法中打印又是返回true,确定是已经登录了哦
如图:
返回的是false
高洛峰2017-05-16 13:00:35
自Laravel 5.3 开始把路由分组以后,就有这个问题了。原因是 construct 运行时 middleware 未运行。
use Closure;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $user;
public function __construct(Request $request)
{
$this->middleware(function($request,Closure $next){
$this->user = Auth::user();
return $next($request);
});
}
}
迷茫2017-05-16 13:00:35
function __construct(Request $request)
{
$this->middleware(function ($request, $next) {
dd(Auth::check());
});
}