Reputation: 1337
I have a quick question, suppose that I have a rout group that looks like below:
/*
|---------------------------------------------------------------------------
| 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 */
});
as you can see the routes are protected by a middleware 'auth', what i wanted to ask is what if that i have few routes from that group that I do not want it to be protected by the middleware, how should i state the exception rule? can i do it like this?
/*
|---------------------------------------------------------------------------
| 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 */
});
or is there an appropriate approach of doing it?
Upvotes: 1
Views: 164
Reputation: 9520
The correct way is to nest the route groups like this:
Route::group(['namespace' => 'Profile'], function() {
// Your non protected routes go here
// ...
Route::group(['middleware' => 'auth'], function(){
// Your protected routes go here
// ...
});
});
When you nest route groups, each child group inherits all parameters from the parent one.
Upvotes: 1