The router sets the group middleware before executing the callback
All routes registered in the callback receive the group middleware
The group middleware is cleared after the callback completes
// Step 1: Group middleware is setRouter::group([\App\Middleware\AuthMiddleware::class], function() { // Step 2: This route receives AuthMiddleware automatically Route::get('/dashboard', 'DashboardController@index');});// Step 3: Group middleware is cleared// This route does NOT have AuthMiddlewareRoute::get('/login', 'AuthController@login');
Aeros does not currently support nested route groups. Each group is independent, and the middleware state is cleared after each group’s callback completes.
Instead of nesting, combine middleware at the route level:
// Instead of nested groups (not supported):// Router::group('auth', function() {// Router::group('admin', function() {// Route::get('/users', 'Admin\UserController@index');// });// });// Do this:Router::group('auth,admin', function() { Route::get('/users', 'Admin\UserController@index');});// Or this:Router::group('auth', function() { Route::get('/users', 'Admin\UserController@index') ->withMiddleware(config('app.middlewares.admin'));});
Organize routes into logical groups based on who can access them (public, authenticated, admin) or what feature they belong to (user management, reporting, API).
Use named middleware
Define middleware groups in your config file and reference them by name. This makes routes more readable and middleware easier to maintain.
Apply restrictive middleware first
Put authentication and authorization middleware before logging or analytics middleware to avoid processing requests from unauthenticated users.
Avoid duplicate middleware
The router automatically prevents applying the same middleware class twice, but be mindful when combining named middleware groups that might overlap.