使用 mcamara 包的 laravel 本地化在根 url 上给出 404 错误

我正在尝试使用 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);

            

        }

网页.php


Route::group([

'prefix' => LaravelLocalization::getCurrentLocale(),

'middleware' => ['localizationRedirect', 'localeViewPath' ]], function(){

   Route::get('/',function(){

     dd('check');

  }); 

}

我收到 404 错误。


波斯汪
浏览 76回答 3
3回答

慕的地6264312

这个步骤对我有用Route::group(['prefix' => LaravelLocalization::setLocale(),'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]],function (){// routes here});然后 1 - 删除引导文件夹中的缓存文件 2- php artisan optimize 3- php artisan route:trans:cache 4- php artisan cache:clear 5-php artisan route:clear

湖上湖

这个问题use \Mcamara\LaravelLocalization\Traits\LoadsTranslatedCachedRoutes;的特征是而不是RouteServiceProviderroute:trans:cacheroute:cache

蝴蝶不菲

转到 bootstrap 文件夹并删除 (config.php) 文件,如果有任何名为 (route.php) 的文件,也从 bootstrap 文件夹中删除它。
打开App,查看更多内容
随时随地看视频慕课网APP