Adding multiple middleware to Laravel route

To assign middleware to a route you can use either single middleware (first code snippet) or middleware groups (second code snippet). With middleware groups you are assigning multiple middleware to a route at once. You can find more details about middleware groups in the docs.

To use both (single middleware & middleware group) you can try this:

Route::group(['middleware' => ['auth', 'web']], function() {
  // uses 'auth' middleware plus all middleware from $middlewareGroups['web']
  Route::resource('blog','BlogController'); //Make a CRUD controller
});

You may also assign multiple middleware to the route:

Route::get('/', function () {
//
})->middleware('first', 'second');

Reference

Tags:

Php

Laravel