chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
394 stars 26 forks source link

Prefixed routes are malformed after route:cache command #68

Closed sc-delanoderooij closed 2 years ago

sc-delanoderooij commented 2 years ago

Describe the bug

When one registers a route with a prefix and the route:cache command has been executed then the registered route uri becomes malformed; the prefix is duplicated and the locale is gone.

Steps to Reproduce

Register prefixed route

Route::prefix('prefix')->group(function() {

    Route::multilingual('/test-route', fn() => 'Test Route')
        ->name('test-route');

});
php artisan route:cache
php artisan route:list --name=test-route

Reproduction output

php artisan route:list --name=test-route
+--------+----------+----------------------+---------------+---------+------------+
| Domain | Method   | URI                  | Name          | Action  | Middleware |
+--------+----------+----------------------+---------------+---------+------------+
|        | GET|HEAD | en/prefix/test-route | en.test-route | Closure |            |
|        | GET|HEAD | fr/prefix/test-route | fr.test-route | Closure |            |
|        | GET|HEAD | nl/prefix/test-route | nl.test-route | Closure |            |
|        | GET|HEAD | sv/prefix/test-route | sv.test-route | Closure |            |
+--------+----------+----------------------+---------------+---------+------------+
php artisan route:cache
Route cache cleared!
Routes cached successfully!
php artisan route:list --name=test-route
+--------+----------+--------------------------+---------------+---------+------------+
| Domain | Method   | URI                      | Name          | Action  | Middleware |
+--------+----------+--------------------------+---------------+---------+------------+
|        | GET|HEAD | prefix/prefix/test-route | nl.test-route | Closure |            |
|        | GET|HEAD | prefix/prefix/test-route | en.test-route | Closure |            |
|        | GET|HEAD | prefix/prefix/test-route | fr.test-route | Closure |            |
|        | GET|HEAD | prefix/prefix/test-route | sv.test-route | Closure |            |
+--------+----------+--------------------------+---------------+---------+------------+
php artisan route:clear
Route cache cleared!
php artisan route:list --name=test-route
+--------+----------+----------------------+---------------+---------+------------+
| Domain | Method   | URI                  | Name          | Action  | Middleware |
+--------+----------+----------------------+---------------+---------+------------+
|        | GET|HEAD | en/prefix/test-route | en.test-route | Closure |            |
|        | GET|HEAD | fr/prefix/test-route | fr.test-route | Closure |            |
|        | GET|HEAD | nl/prefix/test-route | nl.test-route | Closure |            |
|        | GET|HEAD | sv/prefix/test-route | sv.test-route | Closure |            |
+--------+----------+----------------------+---------------+---------+------------+

Additional context

PHP 8.1 Laravel 8.X Branch v2

chinleung commented 2 years ago

This is fixed as of v2.8.2.