Any middleware registered as routeMiddleware
in app/Http/Kernel.php
can be assigned to a route.
There are a few different ways to assign middleware, but they all do the same.
Route::get('/admin', 'AdminController@index')->middleware('auth', 'admin');
Route::get('admin/profile', ['using' => 'AdminController@index', 'middleware' => 'auth']);
Route::get('admin/profile', ['using' => 'AdminController@index', 'middleware' => ['auth', 'admin']);
In all the examples above, you can also pass fully qualified class names as middleware, regardless if it's been registered as a route middleware.
use App\Http\Middleware\CheckAdmin;
Route::get('/admin', 'AdminController@index')->middleware(CheckAdmin::class);