1

i am trying to use mcamara package for language translation but on the root url i am getting 404 error. Actually i am trying to detect the ip address of the user and then set the locale according to that country. i stored the locales and country names in the database. Below is my code:

AppServiceProvider.php in this file i am fetching user ip address through https://github.com/stevebauman/location this package and checking the locale from database and set the locale according to that.

        $ip = request()->getClientIp(); 
        $position = Location::get($ip); 
        $locale = Locale::where('country_code',strtolower($position->countryCode))->first();
        if($locale){
            LaravelLocalization::setLocale($locale->country_code);
            
        }

Web.php

Route::group([
'prefix' => LaravelLocalization::getCurrentLocale(),
'middleware' => ['localizationRedirect', 'localeViewPath' ]], function(){
   Route::get('/',function(){
     dd('check');
  }); 
}

i am getting 404 error.

Naveed Ali
  • 1,043
  • 7
  • 15

3 Answers3

4

this steps works for me

Route::group(['prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]],function (){
// routes here

});

then 1 - remove cache files in bootstrap folder 2- php artisan optimize 3- php artisan route:trans:cache 4- php artisan cache:clear 5- php artisan route:clear

hai_shar
  • 89
  • 4
0

https://github.com/mcamara/laravel-localization/blob/master/CACHING.md

this url help to you. use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes; trait in RouteServiceProvider this problem at route:trans:cache instead of route:cache

Farrux Choriyev
  • 179
  • 1
  • 5
-2

go to bootstrap folder and delete (config.php) file and if there is any file called (route.php) delete it too from bootstrap folder.