简体   繁体   English

如何基于多用户系统防护将用户重定向到其他页面?

[英]How to redirect user to different page based on the guard for multi user system?

In laravel 5.7 there is "Authenticate.php" file that looks like this: 在laravel 5.7中,“ Authenticate.php”文件如下所示:

<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
/**
 * Get the path the user should be redirected to when they are not authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return string
 */
 protected function redirectTo($request)
 {
    if (! $request->expectsJson()) {
        return route('login');
    }
  }
}

I have set admin guard for the admin user type (auth.php): 我已经为管理员用户类型(auth.php)设置了管理员保护:

        */

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],
    'admin-api' => [
        'driver' => 'token',
        'provider' => 'admins',
    ],
],

How can i get the guard type from $request, so that I can check if the $guard name is "admin" set a different redirect page. 我如何从$ request获取防护类型,以便可以检查$ guard名称是否为“ admin”,请设置其他重定向页面。 Most tutorials are not covering 5.7 version yet. 大多数教程尚未涵盖5.7版本。

Thanks a lot in advance 提前谢谢

I think I had your issue, you can follow this question and answer, I hope to help you. 我想我遇到了您的问题,您可以按照以下问答进行,希望对您有所帮助。

How to check multiple gaurd in same laravel controller OR route 如何在同一laravel控制器或路由中检查多个gaurd

https://stackoverflow.com/a/49871781/9246297 https://stackoverflow.com/a/49871781/9246297

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

相关问题 如何根据页面重定向用户? - How to redirect user based on page? 如何根据 WordPress 中的表单条目数将用户重定向到不同的页面 - How to redirect a user to a different page based on the number of form entries in WordPress 多级登录页面根据用户角色php将用户重定向到其他页面 - Multi level login page redirect users to different pages based on user role php 如何在刷新页面时将用户重定向到其他控制器 - How to redirect user to a different controller on refreshing the page 如果用户是第一次登录,如何将用户重定向到某个不同的页面 - How to redirect the user to some different page if user is logging for the first time 如何根据角色将用户重定向到特定网页? - How to redirect user based on role to a specific web page? 如何在php和mysql中按用户类型重定向到不同的页面 - How to redirect into different page by user type in php and mysql 我如何将我的用户和管理员重定向到其他页面 - How can i redirect my user and admin to different page 如何在 php 中基于角色创建多用户(管理员、注册用户、普通访客)登录系统? - How to create multi user (Admin, Registered User, General Visitor) login system on Role Based in php? 根据使用的页面模板重定向用户 - Redirect User based on page template used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM