mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.38k stars 514 forks source link

The localization prefix not working after caching routes. #829

Closed muath-ye closed 2 years ago

muath-ye commented 2 years ago

Describe the bug I install the package with all steps provided in README.md And I used it as followwing:

// routes/web.php

Route::group(['prefix' => LaravelLocalization::setLocale()], function()
{
    /** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
    Route::get('/', function()
    {
        return View::make('hello');
    });

    Route::get('test',function(){
        return View::make('test');
    });
});

To Reproduce Steps to reproduce the behavior:

  1. Execute php artisan route:cache or php artisan optimize
  2. Check http://yourdomain.com/en/any-link
  3. It will not work.
  4. Execute php artisan route:clear
  5. Check http://yourdomain.com/en/any-link
  6. It will work fine.

Expected behavior A clear and concise description of what you expected to happen.

More info:

Additional context I am currently clearing routes to resolve the problem but I can not cache the routes

Djagannath commented 2 years ago

Use trait use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes;

class RouteServiceProvider extends ServiceProvider { use LoadsTranslatedCachedRoutes;

And then run php artisan route:trans:cache

muath-ye commented 2 years ago

Use trait use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes;

class RouteServiceProvider extends ServiceProvider { use LoadsTranslatedCachedRoutes;

And then run php artisan route:trans:cache

@Djagannath it works for me thank you. even with php artisan route:cache. I only need to use LoadsTranslatedCachedRoutes;