Skip to content

Commit 9ea97dc

Browse files
committed
Autoload route() helper function
1 parent 2d65b35 commit 9ea97dc

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

README.md

-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ A convenient way to set up and use localized routes in a Laravel app.
2626
- [Use Fallback Locale](#-use-fallback-locale)
2727
- [Omit Slug for Main Locale](#-omit-slug-for-main-locale)
2828
- [Scoped Options](#-scoped-options)
29-
- [Load Helper Functions](#-load-helper-functions)
3029
- [Add Middleware to Update App Locale](#-add-middleware-to-update-app-locale)
3130
- [Detectors](#detectors)
3231
- [Stores](#stores)
@@ -150,18 +149,6 @@ Route::localized(function () {
150149
]);
151150
```
152151

153-
## 📂 Load Helper Functions
154-
155-
If you would like to use the `route()` helper function to generate localized URLs, you will need to load the helpers file before Laravel's helpers are loaded.
156-
You do this by requiring our `helpers.php` in your `public/index.php` file, right before composer's `autoload.php` is loaded:
157-
158-
```php
159-
require __DIR__.'/../vendor/codezero/laravel-localized-routes/src/helpers.php'; //=> add this line
160-
require __DIR__.'/../vendor/autoload.php';
161-
```
162-
163-
If you don't load the helpers file, you can always generate localized routes using `URL::route()` with Laravel's URL facade.
164-
165152
## 🧩 Add Middleware to Update App Locale
166153

167154
By default, the app locale will always be what you configured in `config/app.php`.

UPGRADE.md

-20
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,6 @@ We dropped support for Laravel 5.6, 5.7, 5.8 and 6.x.
2525

2626
---
2727

28-
### ➡ Manually Load `route()` Helper
29-
30-
If you would like to continue to use the `route()` helper function to generate localized URLs, you will need to load the helpers file before Laravel's helpers are loaded.
31-
32-
This used to be handled automatically by a composer plugin, but this caused an issue for some people.
33-
Once we find a better way to automate this, we will implement it.
34-
35-
If you don't load the helpers file, you can always generate localized routes using `URL::route()` with Laravel's URL facade.
36-
37-
🔸 **Actions Required**
38-
39-
- Require our `helpers.php` in your `public/index.php` file, right before composer's `autoload.php` is loaded:
40-
41-
```php
42-
require __DIR__.'/../vendor/codezero/laravel-localized-routes/src/helpers.php'; //=> add this line
43-
require __DIR__.'/../vendor/autoload.php';
44-
```
45-
46-
---
47-
4828
### ➡ Middleware Changes
4929

5030
Applying the `CodeZero\LocalizedRoutes\Middleware\SetLocale` middleware is now more straightforward.

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"require": {
2323
"php": "^7.2.5|^8.0",
2424
"codezero/browser-locale": "^3.0",
25+
"codezero/composer-preload-files": "^1.0",
2526
"codezero/laravel-uri-translator": "^1.0",
2627
"codezero/php-url-builder": "^1.0",
2728
"illuminate/support": "^7.0|^8.0|^9.0|^10.0"
@@ -50,14 +51,17 @@
5051
"CodeZero\\LocalizedRoutes\\LocalizedRoutesServiceProvider"
5152
]
5253
},
53-
"include_files": [
54+
"preload-files": [
5455
"src/helpers.php"
5556
]
5657
},
5758
"config": {
5859
"preferred-install": "dist",
5960
"sort-packages": true,
60-
"optimize-autoloader": true
61+
"optimize-autoloader": true,
62+
"allow-plugins": {
63+
"codezero/composer-preload-files": true
64+
}
6165
},
6266
"minimum-stability": "dev",
6367
"prefer-stable": true

0 commit comments

Comments
 (0)