Skip to content

Commit a71a1ac

Browse files
[11.x] Add middleware alias registration example for EnsureUserHasRole middleware (laravel#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 <[email protected]>
1 parent 358fd26 commit a71a1ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

middleware.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,17 @@ Additional middleware parameters will be passed to the middleware after the `$ne
394394

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

397+
use App\Http\Middleware\EnsureUserHasRole;
398+
397399
Route::put('/post/{id}', function (string $id) {
398400
// ...
399-
})->middleware('role:editor');
401+
})->middleware(EnsureUserHasRole::class.':editor');
400402

401403
Multiple parameters may be delimited by commas:
402404

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

407409
<a name="terminable-middleware"></a>
408410
## Terminable Middleware

0 commit comments

Comments
 (0)