From 0562f29c32da3de0483c467249def95614693a2c Mon Sep 17 00:00:00 2001 From: Wyatt Castaneda Date: Sat, 19 Oct 2024 23:32:52 -0700 Subject: [PATCH] Update teams-permissions.md Provide an example of pushing your custom middleware before the SubstituteBindings middleware in the applications middleware stack. In the new Laravel skeleton, this method provides a much cleaner approach than copying all default middlewares in the `bootstrap\app.php` `withMiddleware` method. --- docs/basic-usage/teams-permissions.md | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/basic-usage/teams-permissions.md b/docs/basic-usage/teams-permissions.md index f4a0d729..ad220a1a 100644 --- a/docs/basic-usage/teams-permissions.md +++ b/docs/basic-usage/teams-permissions.md @@ -56,6 +56,34 @@ class TeamsPermission **YOU MUST ALSO** set [the `$middlewarePriority` array](https://laravel.com/docs/master/middleware#sorting-middleware) in `app/Http/Kernel.php` to include your custom middleware before the `SubstituteBindings` middleware, else you may get *404 Not Found* responses when a *403 Not Authorized* response might be expected. +For example, in Laravel 11.27+ you can add something similiar to the `boot` method of your `AppServiceProvider`. + +```php +use App\Http\Middleware\YourCustomMiddlewareClass; +use Illuminate\Foundation\Http\Kernel; +use Illuminate\Routing\Middleware\SubstituteBindings; +use Illuminate\Support\ServiceProvider; + +class AppServiceProvider extends ServiceProvider +{ + public function register(): void + { + // + } + + public function boot(): void + { + /** @var Kernel $kernel */ + $kernel = app()->make(Kernel::class); + + $kernel->addToMiddlewarePriorityBefore( + SubstituteBindings::class, + YourCustomMiddlewareClass::class, + ); + } +} +``` + ## Roles Creating When creating a role you can pass the `team_id` as an optional parameter