Register a short-hand name for a middleware.
public middleware ( string $name, string $class ) | ||
$name | string | |
$class | string |
// create a new router instance use Illuminate\Routing\Router; $router = new Router; // define a GET route $router->get('/user/{id}', function ($id) { return 'User '.$id; }); // define a route with middleware $router->get('/profile', [ 'middleware' => 'auth', function () { return 'Authenticated User'; } ]);In the first example, a simple route is defined that matches the pattern `/user/{id}` and returns a string with the value of the `id` parameter. In the second example, a route with a middleware is defined. The `auth` middleware will be applied to this route, and only authenticated users will be able to access the page. This middleware is part of the Laravel framework's routing package, specifically the Illuminate\Routing\Middleware\SubstituteBindings middleware.
public middleware ( string $name, string $class ) | ||
$name | string | |
$class | string |