我正在使用一种带有自定义检查和会话的laravel 5.7身份验证。 我有5种用户类型
Session :: put('user_type',$ user_type); 会话:: put('user_id',$ user_id);
当我尝试在构造函数中检查会话数据时,我面临一个问题,请帮助我解决此问题,
ErrorException(E_NOTICE)试图获取的属性“标头” 非对象
public function __construct()
{
$this->middleware(function ($request, $next) {
$utype=Session::get('user_type');
if($utype != 'ProjectAdmin'){
return redirect()->route('login');
}else{
$this->objShareContract = shareContract::getShareContract(TRUE);
}
});
}
答案 0 :(得分:2)
中间件必须返回响应。您不会从此基于定制Closure的中间件返回响应。您有2条逻辑路径,只有其中一条返回某种响应。
在此中间之前,还有其他中间件期望Response通过管道返回。这就是return $next($request);
的意思。