laravel-localization
laravel-localization copied to clipboard
laravel localization using mcamara package giving 404 error on root url but not other urls
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 on www.example.com but when i do www.example.com/en then it's working fine. Any Help would be really appreciated. i am stuck in it from few days.
go to your bootstrap folder and delete the ( config.php ) and if there is a file called route in the bootstrap folder delete it too
php artisan route:trans:clear
@Naveedali1234 I am also trying the same. But no success. Any solution you found?
Same error
check your RouteServiceProvider if there are prfix assigned to your routes remove it .. if you added a prefix and need it .. move it to routes file itself .. 'prefix' => LaravelLocalization::setLocale() ... this prefix should be the first prefix
In case this will help anyone in the future, routes must not be cached so if you run php artisan route:cache or php artisan optimize locally or after deploying to the server, you will get the 404.
any solution?