简体   繁体   English

登录后如何根据用户在 laravel 中的角色重定向用户

[英]How do I redirect users after logging in based on their role in laravel

In my project, I want to have one table users and a role table to differentiate them with another role table.Can someone tell me how I can set that in my login controller?在我的项目中,我想要一个表用户和一个角色表来区分它们与另一个角色表。有人可以告诉我如何在我的登录 controller 中设置它吗?

A good place to define this is at the LoginController定义它的好地方是LoginController

Override the redirectTo function and return the proper URL based on authenticated user role覆盖redirectTo函数并根据经过身份验证的用户角色返回正确的 URL

Something like this should work像这样的东西应该工作

protected function redirectTo()
{
    return auth()->user()->role->name == 'admin' ? '/dashboard' : '/home';
}

From the docs文档

I hope this helps我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM