AdminMiddleware:
public function handle($request, Closure $next)
{
return $next($request);
if (\Auth::user() && \Auth::user()->isAdmin() == 1) {
return view('adminpage');
} else {
return view('homepage');
}
}
}
user.php的:
public function isAdmin() {
return $this->is_admin;
}
UserController.php:
public function login(Request $request)
{
$email = $request->email;
$password = $request->password;
if(\Auth::attempt(['email'=>$email, 'password'=>$password])) {
// i dont know what if successfull login, i need to execute the logic written in AdminMiddleware
} else {
return view('login);
}
}
我的表包含一个布尔字段" is_admin"使用1
xxx@gmail.com