我有这个中间件:
public function handle($request, Closure $next)
{
$response = $next($request);
$user = $this->auth->getUser();
if ($user->role_id == 1) {
return $response;
} else {
return response('Unauthorized.', 401);
}
}
我想在调用配置文件页面和路由中的代码时使用此中间件:
Route::get('profile', ['middleware' => 'superAdmin', 'uses' => 'users\UserController@index']);
我将它添加到kernel.php中的$ routeMiddleware数组
调用页面时:
http://localhost:8080/public/profile
得到了这个错误:
ErrorException in SuperAdminRoleMiddleware.php line 43: Trying to get property of non-object
第43行是:if($ user-> role_id == 1){
问题是什么: