laravel-将三种不同的用户类型/角色重定向到不同的页面 [英] laravel - redirecting three different user types/roles to different pages
问题描述
我使用laravel 5.4,我想将这三种不同类型的用户重定向到不同的页面
I use laravel 5.4 and I want to redirect these three different types of users to different pages
Types
+-------+-------------+
| id | name |
+-------+-------------+
| 1 | Super Admin |
| 2 | Admin |
| 3 | Cashier |
+-------+-------------+
Users
+-------+---------+-------------+
| id | type_id | name |
+-------+---------+-------------+
| 1 | 1 | Super Admin |
| 2 | 2 | Admin |
| 3 | 3 | Cashier |
+-------+---------+-------------+
我这样写代码
use Auth;
public function redirectTo()
{
$superAdmin = Auth::user()->type_id = 1;
$admin = Auth::user()->type_id = 2;
$cashier = Auth::user()->type_id = 3;
if ($superAdmin) {
return '/superAdmin/home';
}
elseif ($admin) {
return '/admin/home';
}
elseif ($cashier) {
return '/cashier/home';
}
}
但是它总是重定向到'/superAdmin/home',有人可以告诉我我的错吗?
but it always redirects to '/superAdmin/home', can someone tell what my fault is?
推荐答案
尝试了解您在代码中编写的内容 您正在将1分配给$ supseadmin以及 auth :: User()-> type_id
Try to understand what you have written in your code You are assigning 1 to $supseadmin as well as auth::User()->type_id
然后在要检查的if条件下 if($ superadmin){}
Then in the if condition you are checking if($superadmin){}
表示if(1){} 然后,这种类型的if条件仅检查数据是否存在,然后进入您要返回的if语句主体 成为超级管理员
means if(1){} Then this type of if condition just check if the data exists then it goes in to the if statements body where you are returning To super admin
这篇关于laravel-将三种不同的用户类型/角色重定向到不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!