2

I have multiple layouts for the project.

So I'm calling a different layout base on the view requested.

I want to share a variables to a specific layout, and other variables for another one, and so on ..

i.e:

in layouts folder:

1- app.blade

2- base.blade

3- project1.blade

I want to share data to the layouts, without having to hard code these data every time I call a view in the controller:

if any view extend app.blade, then data1 is shared

if any view extend base.blade, then data2 is shared, and so on ..

is there an easy way to achieve this ?

shamaseen
  • 2,193
  • 2
  • 21
  • 35
  • Is this data static? if it is you could use .env vars – hurnhu Nov 27 '19 at 15:42
  • also have you looked at https://stackoverflow.com/questions/29715813/laravel-5-global-blade-view-variable-available-in-all-templates ? it might be a good start – hurnhu Nov 27 '19 at 15:48
  • 2
    Take a look at [view composers](https://laravel.com/docs/master/views#view-composers) – brombeer Nov 27 '19 at 15:54

1 Answers1

-1

You can use this function

In AppserviceProvider.php file boot function

view()->composer(['articles.index', 'articles.show', 'blog.*'], function ($view) {
    $view->with('total', $total);
});
Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
Merdan
  • 1