Laravel 5.2以管理员身份登录后重定向管理员页面 [英] Laravel 5.2 Redirect admin page after login as admin

查看:201
本文介绍了Laravel 5.2以管理员身份登录后重定向管理员页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Laravel 5.2已经发布了一段时间.是的,它具有新的身份验证功能,非常好.特别适合初学者. 我的问题, 如何检查用户是否是admin,然后安全地正确重定向到admin/dashboard?我知道一种方法是在数据库中使用admin标志,但是你们中的任何一个都可以显示一些示例吗?

Laravel 5.2 has been out for some time now. Yes, it has new auth function which is very good. Specially for beginners. My question, How to check if user is admin and then redirect safely to admin/dashboard properly? I know one way is to use admin flag in database but can any of you show some example?

推荐答案

转到AuthController.php并添加此方法

go to AuthController.php and add this method

其中角色是数据库中定义的用户角色.

where role is the user role as defined in the database.

protected function authenticated($request,$user){
    if($user->role === 'admin'){
        return redirect()->intended('admin'); //redirect to admin panel
    }

    return redirect()->intended('/'); //redirect to standard user homepage
}

这篇关于Laravel 5.2以管理员身份登录后重定向管理员页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆