简体   繁体   English

Laravel 9 根据角色将登录重定向到不同的视图

[英]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.有很多关于这方面的教程,但我认为它们不适合 Laravel 9 - 大多数是指我没有的LoginController.php

I have another Laravel project that does have LoginController.php and redirects, but it's an older version of Laravel.我有另一个 Laravel 项目,它确实有 LoginController.php 和重定向,但它是 Laravel 的旧版本。

Can anyone point me in the right direction for version 9?任何人都可以为我指出第 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查看 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.由于此代码在您的应用程序中(不在供应商中),您可以根据用户的角色更改最后一行以重定向到 go 的任何位置。

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

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