@@ -340,10 +340,20 @@ use the `middleware` method:
340
340
$server->resource('posts')->middleware('my_middleware1', 'my_middleware2');
341
341
```
342
342
343
- ::: tip
344
- If you want to add middleware to specific resource actions, you should
345
- use [ Controller middleware.] ( https://laravel.com/docs/controllers#controller-middleware )
346
- :::
343
+ Alternatively, you can specify middleware per resource action. To do that,
344
+ provide an array to the ` middleware() ` method. Middleware that applies to
345
+ every action should use the ` "*" ` key. Middleware for a specific action
346
+ should be keyed by that action.
347
+
348
+ For example:
349
+
350
+ ``` php
351
+ $server->resource('posts')->middleware([
352
+ '*' => 'my_middleware1', // applies to all actions
353
+ 'show' => 'my_middleware2', // apples to just the "show" action
354
+ 'store' => ['my_middleware3', 'my_middleware4'], // use arrays for multiple
355
+ ]);
356
+ ```
347
357
348
358
## Defining Relationships
349
359
@@ -449,6 +459,22 @@ The following example adds middleware to our `tags` relationship routes:
449
459
$relationships->hasMany('tags')->middleware('my_middleware1', 'my_middleware2');
450
460
```
451
461
462
+ Alternatively, you can specify middleware per relationship action. To do that,
463
+ provide an array to the ` middleware() ` method. Middleware that applies to
464
+ every relationship action should use the ` "*" ` key. Middleware for a specific
465
+ action should be keyed by that action. Use our short-hands of ` related ` ,
466
+ ` show ` , ` update ` , ` attach ` and ` detach ` for the actions:
467
+
468
+ For example:
469
+
470
+ ``` php
471
+ $relationships->hasMany('tags')->middleware([
472
+ '*' => 'my_middleware1', // applies to all actions
473
+ 'show' => 'my_middleware2', // apples to just the "show" action
474
+ 'update' => ['my_middleware3', 'my_middleware4'], // use arrays for multiple
475
+ ]);
476
+ ```
477
+
452
478
## Route Model Binding
453
479
454
480
By default Laravel takes care of substituting parameter values for models using
0 commit comments