1
1
# Laravel Localizer
2
2
3
3
[ ![ GitHub release] ( https://img.shields.io/github/release/codezero-be/laravel-localizer.svg?style=flat-square )] ( https://github.com/codezero-be/laravel-localizer/releases )
4
- [ ![ Laravel] ( https://img.shields.io/badge/laravel-10 -red?style=flat-square&logo=laravel&logoColor=white )] ( https://laravel.com )
4
+ [ ![ Laravel] ( https://img.shields.io/badge/laravel-11 -red?style=flat-square&logo=laravel&logoColor=white )] ( https://laravel.com )
5
5
[ ![ License] ( https://img.shields.io/packagist/l/codezero/laravel-localizer.svg?style=flat-square )] ( LICENSE.md )
6
6
[ ![ Build Status] ( https://img.shields.io/github/actions/workflow/status/codezero-be/laravel-localizer/run-tests.yml?style=flat-square&logo=github&logoColor=white&label=tests )] ( https://github.com/codezero-be/laravel-localizer/actions )
7
7
[ ![ Code Coverage] ( https://img.shields.io/codacy/coverage/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square )] ( https://app.codacy.com/gh/codezero-be/laravel-localizer )
@@ -19,8 +19,8 @@ Automatically detect and set an app locale that matches your visitor's preferenc
19
19
20
20
## ✅ Requirements
21
21
22
- - PHP >= 7.2.5
23
- - Laravel >= 7 .0
22
+ - PHP >= 8.1
23
+ - Laravel >= 10 .0
24
24
25
25
## ⬆ Upgrade
26
26
@@ -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
//...
0 commit comments