dimanche 23 juin 2019

Laravel dose not update locale (language) in class constructor

i just want to share some variables globally in all my blades , i use view share to do this work, my website is multilang and i just wan to get locale in every request

i use class constructor to share variables but everytime ichange the language my locale is not change in constructor and return just previous locale

here is my constructor in my HomeController

public function __construct()
{
    $lang = app()->getLocale();
    $logo = Media::where('lang',$lang)->where('title','header_logo')- 
    >first();
    $header = Header::where('lang',$lang)->first();
    $socials = Social::where('lang',$lang)->get();

    $data = [
        'logo' => $logo,
        'header' => $header,
        'socials' => $socials,
    ];

    \View::share($data);
}

i just want to get the last locale in $lang variable, but nothing change in every request that i changed the language please help me to share those variables to all my blades thanks alot



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire