1//create a service provider
2php artisan make:provider ComposerServiceProvider
3
4//register the app service provider in providers array of config/app.php
5App\Providers\ComposerServiceProvider::class,
6
7//pass the data you want to share in views
8<?php
9namespace App\Providers;
10use Illuminate\Support\Facades\View;
11use Illuminate\Support\ServiceProvider;
12
13class ComposerServiceProvider extends ServiceProvider {
14
15 public function boot()
16 {
17 View::composer('*', function($view){
18 $data = Some logic here ; //eg User::all();
19 $view->with('data', $data); // 'data' is value to be used in views 'data' = $data
20 });
21 }
22
23 public function register()
24 {
25 //
26 }
27}
28