laravel5.4 多用户认证

作者: hyperbolaa | 来源:发表于2017-04-26 01:23 被阅读100次

未登录重定向 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');
}

相关文章

网友评论

    本文标题:laravel5.4 多用户认证

    本文链接:https://www.haomeiwen.com/subject/kugbzttx.html