File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,36 @@ Laravel will automatically register the ServiceProvider.
39
39
40
40
## 🧩 Add Middleware
41
41
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.
43
44
Make sure to add it after ` StartSession ` and before ` SubstituteBindings ` .
44
45
45
46
The order of the middleware is important if you are using localized route keys (translated slugs)!
46
47
The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.
47
48
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
+
48
70
``` php
71
+ // app/Http/Kernel.php
49
72
protected $middlewareGroups = [
50
73
'web' => [
51
74
//...
You can’t perform that action at this time.
0 commit comments