Registering Middleware: Middleware Groups
Middleware Groups
Again, middleware groups make it more convenient to assign many middleware to a route at once.
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'auth:api',
],
]; Route::get('/', function () {
//
})->middleware('web');
Route::group(['middleware' => ['web'] ], function () {
//
}); - May be assigned to routes and controller actions using the same syntax as individual middleware.
- Out of the box, the web middleware group is automatically applied to your routes/web.php file by the RouteServiceProvider.
- Out of the box, Laravel comes with web and api middleware groups that contain common middleware you may want to apply to your web UI and API routes.
Semantic portal