Luc*_*die 7 laravel-routing laravel-5
我最近开始使用Laravel 5,我在实现一个不仅授权用户,还检查权限的系统时遇到了很多麻烦.
在我在网上挖掘的所有例子中,我看到有两个项目被用作中间件.例如:
Route::group(['middleware' => ['auth', 'permissions']], function() {
// protected routes here
Route::get('admin', 'DashboardController@index');
});
Run Code Online (Sandbox Code Playgroud)
但是,无论我做什么,我都无法工作.我只能将一个项目用作中间件,例如:
Route::group(['middleware' => 'auth'], function() {
// protected routes here
Route::get('admin', 'DashboardController@index');
});
Run Code Online (Sandbox Code Playgroud)
如果我应用两个,我收到错误"Route [admin] not defined."
我已经尝试了所有我能想到的东西,而且我正撞在一堵砖墙上.我怎么能在一条路线上应用两件或两件以上的中间件呢?
我正在回答我自己的问题,因为很多人错过了提到解决方案的评论。
The issue was in the Permissions middleware, as mentioned in the comment made by lukasgeiter.
As seen in my reply, the answer was found in the permissions middleware, where was using:
return redirect()->route('admin');
Run Code Online (Sandbox Code Playgroud)
instead of:
redirect('admin');
Run Code Online (Sandbox Code Playgroud)
There was actually nothing wrong with the code in my routes.php file.
| 归档时间: |
|
| 查看次数: |
9748 次 |
| 最近记录: |