Nav*_*Ali 1 php laravel laravel-localization
我正在尝试使用 mcamara 包进行语言翻译,但在根 url 上我收到 404 错误。实际上我正在尝试检测用户的 IP 地址,然后根据该国家/地区设置区域设置。我将区域设置和国家/地区名称存储在数据库中。下面是我的代码:
AppServiceProvider.php在这个文件中,我通过https://github.com/stevebauman/location这个包获取用户 IP 地址,并从数据库检查区域设置并根据该区域设置设置区域设置。
$ip = request()->getClientIp();
$position = Location::get($ip);
$locale = Locale::where('country_code',strtolower($position->countryCode))->first();
if($locale){
LaravelLocalization::setLocale($locale->country_code);
}
Run Code Online (Sandbox Code Playgroud)
网页.php
Route::group([
'prefix' => LaravelLocalization::getCurrentLocale(),
'middleware' => ['localizationRedirect', 'localeViewPath' ]], function(){
Route::get('/',function(){
dd('check');
});
}
Run Code Online (Sandbox Code Playgroud)
我收到 404 错误。
小智 5
这个步骤对我有用
Route::group(['prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]],function (){
// routes here
Run Code Online (Sandbox Code Playgroud)
});
然后 1 - 删除引导文件夹中的缓存文件 2- php artisan optimize
3- php artisan route:trans:cache
4- php artisan cache:clear
5-php artisan route:clear
| 归档时间: |
|
| 查看次数: |
2454 次 |
| 最近记录: |