我正在创建AdminAuthenticated中间件
public function handle($request, Closure $next)
{
if (Auth::user()->role->name == 'customer') {
return redirect('/home')->with('message', 'You are not allowed to access');
}
return $next($request);
}
当我使用雄辩的关系时,它将正常工作,但是当我使用查询生成器时,其抛出错误我的问题是
此代码有效
public function role(){
//this code work
return $this->belongsTo('App\Role');
}
此代码引发错误,为什么会发生,以及如何在下面的代码中使用(查询生成器)
public function role(){
//this code not work throw exception
return DB::table('users')
->join('roles', 'roles.id', '=', 'users.role_id')
->select('roles.*')
->where('users.id','=',$this->id);
}
我正在创建AdminAuthenticated中间件公共功能句柄($ request,Closure $ next){如果(Auth :: user()-> role-> name =='customer'){return redirect('/ home')-& ...