LNMP集合laravelPHP实战

laravel5.4 多用户认证

2017-04-26  本文已影响100人  hyperbolaa

未登录重定向 Handler.php

 protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }

    $guards = $exception->guards();
    if(is_array($guards) && !empty($guards)){
        foreach ($guards as $guard) {
            if ($guard == 'admin') {
                return redirect()->guest('admin/login');
            } else {
                return redirect()->guest('login');
            }
        }
    }

    return redirect()->guest(route('login'));
}

控制器

Paste_Image.png

登录成功跳转 Middleware/RedirectIfAuthenticated.php

Paste_Image.png

视图

Paste_Image.png

配置文件 config/auth.php

Paste_Image.png Paste_Image.png

退出备注

public function logout()
{
    $this->guard()->logout();
    return redirect('admin/login');
}
上一篇 下一篇

猜你喜欢

热点阅读