Blog

How to assign multiple middleware to Laravel route?

Answer A)
Route::get(‘/’, function () {
// code
})->middleware(‘firstMiddleware’, ‘secondMiddleware’);

Answer B)
Route::get(‘/’, function () {
// code
})->middleware([‘firstMiddleware’, ‘secondMiddleware’]);

Answer C)
Route::get(‘/’, [‘firstMiddleware’, ‘secondMiddleware’], function () {
// code
})->middleware();

Answer D)
Route::get(‘/’, [‘firstMiddleware’, ‘secondMiddleware’], function () {
// code
});