简体   繁体   English

Laravel-将管理员用户路由到子域

[英]Laravel - Route admin user to subdomain

I am building a website with Laravel where a user can be assigned as an admin. 我正在使用Laravel构建网站,可以在其中分配用户作为管理员。 The admins should only navigate through the dashboard which will be under a subdomain admin.domain.com and the other users can only navigate through the main domain domain.com . 管理员只能在子域admin.domain.com下的仪表板中导航,而其他用户只能在主域domain.com中导航。

My question is how can i restrict the admin to view the section where normal users can and vice versa. 我的问题是如何限制管理员查看普通用户可以访问的部分,反之亦然。 I want admins to navigate only through all subdomain routes only (for example admin.domain.com/statistics ) and not domain.com/categories . 我希望管理员仅浏览所有子域路由(例如admin.domain.com/statistics ),而不浏览domain.com/categories These are my routes for the admin and public part. 这些是我的管理员和公共部分的路线。

Route::group(['domain' => 'admin.domain.com'], function () {
    /* Admin routes */
});

Route::group(['domain' => 'domain.com'], function () {
    /* Public routes */
}

I want when i login as an admin to be automatically redirected to the subdomain and if i type a public route i want to be redirected back to the root admin route. 我想以管理员身份登录时自动重定向到子域,如果我键入公共路由,我想重定向回根管理路由。

One of the solutions i was thinking was to wrap the admin and public routes with a middleware that will redirect the user depending on its type whether its admin or normal user but im not sure if this is a proper solution. 我正在考虑的解决方案之一是用中间件包装admin和公共路由,该中间件将根据用户的类型(用户是admin还是普通用户)来重定向用户,但不确定这是否合适。

Thanks 谢谢

You Could Use 2 Middlewares 您可以使用2个中间件

1- redirect non-admins to public area will be placed in the first group 1-将非管理员重定向到公共区域将放在第一组中

2- redirect admins to admins subdomain will be placed in the second group 2-将管理员重定向到管理员子域将被放置在第二组中

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

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