DEV Community

Saroz Kumar
Saroz Kumar

Posted on

Multiple Authentication in laravel 6x

i have installed laravel default authentication system (using php artisan ui react --auth) which is best for me but i have created different table for user role and make relationship between user and role table and create new table called role_user but i am unable to redirect a different page based on user role in roles table. So, my question is how to redirect pages for different user based on role? I couldn't change the default /home page, in my condition all user role redirected to same /home page.

Top comments (2)

Collapse
 
msamgan profile image
Mohammed Samgan Khan •

the easiest way to do this to use the authenticated event which is fired after the authentication take place.

in you LoginController add

   /**
     * @param Request $request
     * @param $user
     * @return RedirectResponse
     */
    protected function authenticated(Request $request, $user)
    {
        if ($user->role === "ADMIN") {
            return redirect('/admin-page');
        }

        return redirect('/user-page');
    }

Some comments may only be visible to logged-in visitors. Sign in to view all comments.