Laravel 5 路由组中过滤器的异常路由
Laravel 5 exception routes from filter in route groups
我有一个简单的问题,假设我有一个如下所示的溃败组:
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group(['middleware' => 'auth', 'namespace' => 'Profile'], function(){
/* Do something here */
});
如您所见,路由受中间件 'auth' 保护,我想问的是,如果我不希望它受中间件保护的那组路由很少怎么办,我应该如何陈述例外规则?我可以这样做吗?
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group(['middleware' => 'auth', 'namespace' => 'Profile'], function(){
/* Do something here */
});
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are not protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group('namespace' => 'Profile', function(){
/* Do something unprotected here */
});
或者有合适的方法吗?
正确的方法是这样嵌套路由组:
Route::group(['namespace' => 'Profile'], function() {
// Your non protected routes go here
// ...
Route::group(['middleware' => 'auth'], function(){
// Your protected routes go here
// ...
});
});
嵌套路由组时,每个子组都会继承父组的所有参数。
我有一个简单的问题,假设我有一个如下所示的溃败组:
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group(['middleware' => 'auth', 'namespace' => 'Profile'], function(){
/* Do something here */
});
如您所见,路由受中间件 'auth' 保护,我想问的是,如果我不希望它受中间件保护的那组路由很少怎么办,我应该如何陈述例外规则?我可以这样做吗?
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group(['middleware' => 'auth', 'namespace' => 'Profile'], function(){
/* Do something here */
});
/*
|---------------------------------------------------------------------------
| The following correspondent routes are namespaced to 'Profile'
| and all controlles under the respective folder.
|
| Routes are not protected by milldeware 'auth'
|---------------------------------------------------------------------------
*/
Route::group('namespace' => 'Profile', function(){
/* Do something unprotected here */
});
或者有合适的方法吗?
正确的方法是这样嵌套路由组:
Route::group(['namespace' => 'Profile'], function() {
// Your non protected routes go here
// ...
Route::group(['middleware' => 'auth'], function(){
// Your protected routes go here
// ...
});
});
嵌套路由组时,每个子组都会继承父组的所有参数。