How do you pass dynamic data to all views in Laravel?

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!

Related Interview Questions