chinleung / laravel-multilingual-routes

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

Home routes not working #28

Closed chmoelders closed 4 years ago

chmoelders commented 4 years ago

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.

chinleung commented 4 years ago

@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.

itsnunolemos commented 4 years ago

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

chmoelders commented 4 years ago

I successfully tried v1.5.1 and v2.0.1.

@itsnunolemos can you confirm this?

itsnunolemos commented 4 years ago

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
chmoelders commented 4 years ago

@chinleung thanks for the fast reply and the fix