简体   繁体   中英

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?

A good place to define this is at the LoginController

Override the redirectTo function and return the proper URL based on authenticated user role

Something like this should work

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

From the docs

I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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