Skip to content

Commit 28a9442

Browse files
authored
Merge pull request #2740 from WyattCast44/patch-1
[Docs] Example of pushing custom middleware before SubstituteBindings middleware
2 parents 9e3a4bb + 0562f29 commit 28a9442

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/basic-usage/teams-permissions.md

Lines changed: 28 additions & 0 deletions
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)