【发布时间】:2018-09-08 05:35:42
【问题描述】:
我在laravel 应用程序中有大约 10 种用户角色,例如
user_type_1 and user_type 4 are accessing url-1.
user_type_7, user_type_5 and user_type 4 are accessing url-2.
user_type_5, user_type_1, user_type_3 and user_type 6 are accessing url-3.
............................................
............................................
n number of combination of routes. url according to user type.
我的route/web.php 文件有大约 1500 条路由,目前没有使用中间件分隔为组。我必须将用户限制为仅对那种 user_type 授权的 url。您能否建议任何更好的方法来执行此操作。
我曾尝试将 url 与下面的中间件组组合在一起,但经过一些工作后,这种方法就离开了。
Route::group(['middleware' => ['middleware_user_type_1', 'middleware_user_type_2']], function () {
Route::get('url-1', 'XYZController@someMethod');
});
以这种方式,请求首先进入数组中的第一个中间件,如果用户类型无效,则不要尝试使用第二个中间件。
【问题讨论】:
-
您是否在控制器的
__construct()中尝试过这个?您是否已正确配置角色和用户以在中间件阵列中单独指定它们?你有 Laratrust 吗?或保镖或Spatie?
标签: php laravel routes laravel-routing laravel-middleware