How to assign a variable value for all view file?

For this you have to get value & assign value in controller file in __construct() like this.



public function __construct() {       
        $this->middleware(function ($request, $next) {              
            $name = session()->get('businessinfo.name');  // get value from session
            View::share('user_name', $name);                   // set value for all View
            View::share('user_email', session()->get('businessinfo.email'));            
            return $next($request);

Suggest An Answer

No suggestions avaliable!

Latest post from Laravel Interview Questions

Ask Question