Skip to content

Commit

Permalink
[11.x] Add middleware alias registration example for EnsureUserHasRol…
Browse files Browse the repository at this point in the history
…e middleware (#9906)

* [11.x] Add middleware alias registration example for EnsureUserHasRole middleware

This commit adds information about registering a middleware alias for the `EnsureUserHasRole` middleware example in the "Middleware Parameters" section of the documentation.

The current documentation provides an example of the `EnsureUserHasRole` middleware and how to use it with parameters, but it doesn't mention the necessary step of registering the middleware alias. This addition will help users avoid confusion when implementing the middleware in their applications.

Changes made:
1. Added a code snippet demonstrating how to register the `EnsureUserHasRole` middleware alias in the `bootstrap/app.php` file.
2. Placed the new information immediately after the middleware class example and before the route definition examples.

* Update middleware.md

* Update middleware.md

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
renato-cardoso and taylorotwell authored Sep 19, 2024
1 parent 358fd26 commit a71a1ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,17 @@ Additional middleware parameters will be passed to the middleware after the `$ne

Middleware parameters may be specified when defining the route by separating the middleware name and parameters with a `:`:

use App\Http\Middleware\EnsureUserHasRole;

Route::put('/post/{id}', function (string $id) {
// ...
})->middleware('role:editor');
})->middleware(EnsureUserHasRole::class.':editor');

Multiple parameters may be delimited by commas:

Route::put('/post/{id}', function (string $id) {
// ...
})->middleware('role:editor,publisher');
})->middleware(EnsureUserHasRole::class.':editor,publisher');

<a name="terminable-middleware"></a>
## Terminable Middleware
Expand Down

0 comments on commit a71a1ac

Please sign in to comment.