0

I'm new at Laravel and trying to make the variable of content at the header shared with all views, but the issue is with getting the language which backing with me with null value at the provider (AppServiceProvider) class.

Here's my code :

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);    
}
4

1 回答 1

0

片段有几个问题:

  • share()方法只需要两个参数而不是重复的键值对
  • 预期的值language是 的结果Session::get("language", $locale),但实际放入的是字符串' \Session::get("language", $locale )'。

基于此,您需要重写如下

view()->share('products', $products);
view()->share('language', Session::get('language', $locale));
view()->share('postId', $postId);
于 2017-02-15T15:57:01.790 回答