Skip to content

Commit f5e29b4

Browse files
committed
Add Laravel 11 middleware instructions to README
1 parent d685748 commit f5e29b4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,36 @@ Laravel will automatically register the ServiceProvider.
3939

4040
## 🧩 Add Middleware
4141

42-
Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.
42+
By default, the app locale will always be what you configured in `config/app.php`.
43+
To automatically update the app locale, you need to register the middleware in the `web` middleware group.
4344
Make sure to add it after `StartSession` and before `SubstituteBindings`.
4445

4546
The order of the middleware is important if you are using localized route keys (translated slugs)!
4647
The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.
4748

49+
### Laravel 11 and newer:
50+
51+
Add the middleware to the `web` middleware group in `bootstrap/app.php`.
52+
53+
```php
54+
// bootstrap/app.php
55+
->withMiddleware(function (Middleware $middleware) {
56+
$middleware->web(remove: [
57+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
58+
]);
59+
$middleware->web(append: [
60+
\CodeZero\Localizer\Middleware\SetLocale::class,
61+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
62+
]);
63+
})
64+
```
65+
66+
### Laravel 10:
67+
68+
Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.
69+
4870
```php
71+
// app/Http/Kernel.php
4972
protected $middlewareGroups = [
5073
'web' => [
5174
//...

0 commit comments

Comments
 (0)