1use Illuminate\Support\Facades\View;
2
3class BaseController extends Controller
4{
5 public function __construct()
6 {
7 //its just a dummy data object.
8 $user = User::all();
9
10 // Sharing is caring
11 View::share('user', $user);
12 }
13}
14
1namespace App\Providers;
2use Illuminate\Support\Facades\View;
3use Illuminate\Support\ServiceProvider;
4use Illuminate\Support\Facades\Schema;
5
6use Illuminate\Support\Facades\Auth;
7use DB;
8
9
10class AppServiceProvider extends ServiceProvider
11{
12 /**
13 * Bootstrap any application services.
14 *
15 * @return void
16 */
17 public function boot()
18 {
19 View::share('key', 'value');
20 Schema::defaultStringLength(191);
21
22 $categories=DB::table('categories')->get();
23 View::share('categories',$categories);
24
25 }
26
27 /**
28 * Register any application services.
29 *
30 * @return void
31 */
32 public function register()
33 {
34 //
35 }
36}
37
1# app/Providers/AppServiceProvider.php
2
3public function boot()
4{
5 // add this
6 view()->share('someKey', 'This is shared data');
7}