Skip to content

[10.x] Add using method for route in middleware #8744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ You may assign multiple middleware to the route by passing an array of middlewar
// ...
})->middleware([First::class, Second::class]);

Also, you can use `using` method for set guards, set relative or absolute URL, set redirect and set rate limiter name for middleware:

```php
Route::get('/', function () {
// ...
})->middleware([
First::using('web'), // specify a guard
First::using('web', 'another'), // specify multiple guards

Second::using('web', 'field'), // specify field

Third::redirectTo('route.name'), // specify a redirect.

Forth::relative(), // relative URL.
Forth::absolute(), // absolute URL. This is the default, but provided a named method for completeness.

Fifth::using('gold-tier'), // named rate limiter
Fifth::with(100, 1, 'foo'), // custom with attempts, decay, and prefix
Fifth::with(prefix: 'foo'), // supports named arguments.
]);
```

For convenience, you may assign aliases to middleware in your application's `app/Http/Kernel.php` file. By default, the `$middlewareAliases` property of this class contains entries for the middleware included with Laravel. You may add your own middleware to this list and assign it an alias of your choosing:

// Within App\Http\Kernel class...
Expand Down