Home > database >  Laravel 9 redirect login to different views based on role
Laravel 9 redirect login to different views based on role

Time:09-15

There's loads of tutorials on this but I don't think they're correct for Laravel 9 - most refer to a LoginController.php that I don't have.

I have another Laravel project that does have LoginController.php and redirects, but it's an older version of Laravel.

Can anyone point me in the right direction for version 9? My roles system is very basic - the users table has a string column (called "type") containing the role name, and that's it.

CodePudding user response:

Have a look in Controllers/Auth/AuthenticatedSessionController.php

Here you will see;

    public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(RouteServiceProvider::HOME);
    }

The last line of which is doing the redirect. Since this code is in your app (not in vendor), you can change the last line to redirect to wherever you want to go based on the user's role.

  • Related