chinleung/laravel-multilingual-routes

Home routes not working

chmoelders opened this issue · 5 comments

Hi!
The package looks pretty cool but I can't get it work.

The multilingual route "en/" doesn't work. Each GET request to http://localhost/en results in a 404.
A GET request to http://localhost/ works fine.

To Reproduce
Laravel v6.12.0 (fresh and clean)
Problem occurs on apache and nginx. First i suspected a problem with the mod_rewrite in apache.
I've tried laravel-multilingual-routes v1.5.0 and 2.0.0

web.php

Route::multilingual('/', function(){
    return current_route();
})->name('home');

Config values

app.locale => 'de'
app.fallback_locale => 'de'
locales.supported => ['de', 'en']
MULTILINGUAL_ROUTES_DEFAULT_LOCALE=de
MULTILINGUAL_ROUTES_PREFIX_DEFAULT=false

Expected behavior
Each route should return its URI

Result of route:list:

+--------+----------+-----+---------+---------+------------+
| Domain | Method   | URI | Name    | Action  | Middleware |
+--------+----------+-----+---------+---------+------------+
|        | GET|HEAD |     | de.home | Closure | web        |
|        | GET|HEAD | en/ | en.home | Closure | web        |
+--------+----------+-----+---------+---------+------------+

Additional
With MULTILINGUAL_ROUTES_PREFIX_DEFAULT=true every route leads to a 404.

@chmoelders Hmmm... that's strange. Not sure why it is resulting as 404 even though it is clearly registered in the router.

I'll investigate later, but for the moment, I've pushed a fix to v2.0.1 and v1.5.1.

Same problem here. All routes with MULTILINGUAL_ROUTES_PREFIX_DEFAULT=true go to 404.

I successfully tried v1.5.1 and v2.0.1.

@itsnunolemos can you confirm this?

I started again with last version and it worked. First I removed the package from vendor and next, I followed the installation:

  1. composer require chinleung/laravel-multilingual-routes
  2. Add in app/Http/Kernel the line \ChinLeung\MultilingualRoutes\DetectRequestLocale::class
  3. php artisan vendor:publish --provider="ChinLeung\MultilingualRoutes\MultilingualRoutesServiceProvider" --tag="config"
  4. php artisan vendor:publish --provider="ChinLeung\LaravelLocales\LaravelLocalesServiceProvider" --tag="config"
  5. In config/laravel-multilingual-routes.php change lines for 'default' => env('MULTILINGUAL_ROUTES_DEFAULT_LOCALE', config('app.locale')), and 'prefix_default' => env('MULTILINGUAL_ROUTES_PREFIX_DEFAULT', true)
  6. In config/locales.php add new language in array
  7. In routes/web.php add Route::redirect('/', locale()); in the top of file

@chinleung thanks for the fast reply and the fix