Skip to content

Commit 0562f29

Browse files
authored
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.
1 parent 43bc084 commit 0562f29

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/basic-usage/teams-permissions.md

+28
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ class TeamsPermission
5656

5757
**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.
5858

59+
For example, in Laravel 11.27+ you can add something similiar to the `boot` method of your `AppServiceProvider`.
60+
61+
```php
62+
use App\Http\Middleware\YourCustomMiddlewareClass;
63+
use Illuminate\Foundation\Http\Kernel;
64+
use Illuminate\Routing\Middleware\SubstituteBindings;
65+
use Illuminate\Support\ServiceProvider;
66+
67+
class AppServiceProvider extends ServiceProvider
68+
{
69+
public function register(): void
70+
{
71+
//
72+
}
73+
74+
public function boot(): void
75+
{
76+
/** @var Kernel $kernel */
77+
$kernel = app()->make(Kernel::class);
78+
79+
$kernel->addToMiddlewarePriorityBefore(
80+
SubstituteBindings::class,
81+
YourCustomMiddlewareClass::class,
82+
);
83+
}
84+
}
85+
```
86+
5987
## Roles Creating
6088

6189
When creating a role you can pass the `team_id` as an optional parameter

0 commit comments

Comments
 (0)