I'm trying to create a group Route for the admin section and apply the middleware to all paths except for login and logout.
What I have so far is:
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => 'authAdmin'], function() {
Route::resource('page', 'PageController');
Route::resource('article', 'ArticleController');
Route::resource('gallery', 'GalleryController');
Route::resource('user', 'UserController');
// ...
});
How would I declare exceptions for the middleware with the above setup?
All the group routes where we apply the concept of Group middleware inside application must be needs to go with filter funnel i.e middleware and then process next. By the help of php artisan command, we create Middleware in laravel. Middlewares will be stored inside /app/Http/Middleware.
Simply said, GET is usually used for presenting/viewing something, while POST is used to change something. For example, when you fetching data for some user you use GET method and it'll look something like this: Route::get('users/{id}', function($id) { $user = \App\User::find($id); echo "Name: " .
You can assign multiple middlewares to Laravel route by using middleware method. Route::group(['middleware' => ['firstMiddleware','secondMiddleware']], function () { // }); This post is submitted by one of our members.
Simply nest groups and then you can exclude specific routes:
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
Route::get('login', 'AuthController@login');
Route::get('logout', 'AuthController@logout');
Route::group(['middleware' => 'authAdmin'], function(){
Route::resource('page', 'PageController');
Route::resource('article', 'ArticleController');
Route::resource('gallery', 'GalleryController');
Route::resource('user', 'UserController');
// ...
});
});
You can also use laravel's withoutMiddleware method as below;
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => 'authAdmin'], function() {
Route::resource('page', 'PageController');
Route::resource('article', 'ArticleController');
Route::resource('gallery', 'GalleryController');
Route::resource('user', 'UserController');
Route::get('login', 'AuthController@login')->withoutMiddleware([AuthAdminMiddleware::class]);
Route::get('logout', 'AuthController@logout')->withoutMiddleware([AuthAdminMiddleware::class]);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With