简体   繁体   中英

Laravel 9 redirect login to different views based on role

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.

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.

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