0
私はLaravelで新しく、ヘッダーのコンテンツの変数をすべてのビューと共有しようとしていますが、問題は、プロバイダ(AppServiceProvider)クラス。ここでLaravelのプロバイダクラスでロケール言語を取得する
は私のコードです:
public function boot()
{
// $language=App::setLocale($locale);
$locale = App::getLocale();
\Session::put('language', 'en');
\Config::get('app.locale');
\Config::get('languages') ;
\Session::get('languages', 'en');
$lang = Session::get ('locale');
$products = ProductsTranslation::join('products', 'products.id', '=', 'products_translations.product_id')->where('language',$lang) ->get();
$postId = Post::get();
view()->share('products', $products,'language',' \Session::get("language", $locale)','postId',$postId);
}
あなたはより良いあなたの問題を説明することはできますが、次のように書き換える必要だろうか?あなたは何を見たいと思っていたのですか?代わりにあなたは何を見ましたか? –
私のフッターでproduct変数を使用しようとしています(ビューごとに共有されています)。 このクエリを使用した場合: $ products = ProductsTranslation :: join( 'products'、 'products.id'、 '='、 'products_translations.product_id') - > get(); 私は使用されている言語の両方ですべての製品を手に入れています。 config \ Config :: get( 'languages')を使った後でも、where( 'language'、$ lang)を使って現在の言語の言語だけを取得し、$ lang変数をnullに戻す必要があります。 ; –
設定に 'languages'がありますか? –