Pass data to all views in Laravel

Pass data to view file Laravel blade

Method 1 : On AppServiceProvider add the following lines

public function boot() {
    view()->share('welcome', "Welcome to my page");
}

Method 2 : Using View Composer

 public function boot(){
        view()->composer('*', function ($view)
{

            $view->with('welcome', Welcome to my page);
        });
    }

One thought on “Pass data to all views in Laravel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s