If we want a middleware to be run during every HTTP request to our application, simply need to list the middleware class in the $middleware
property of your app/Http/Kernel.php
class.
If you would like to assign middleware to specific routes, you should first assign the middleware a short-hand key in your app/Http/Kernel.php
file. By default, the $routeMiddleware
property of this class contains entries for the middleware included with Laravel. To add your own, simply append it to this list and assign it a key of your choosing.
Once the middleware has been defined in the HTTP kernel, you may use the middleware
key in the route options array:
Route::get('admin/profile', ['middleware' => 'auth', function()
{
//
}]);