Data submitted for viewing not available in layout - Laravel controllers

If I have it in the controller

$this->layout->nest('content', 'home.index', $array);

I can only access the data in the $arraytemplate file home.index.blade.php and NOT in layouts.mainwhich I use.

The layout and view load correctly, I just can’t access the data transferred in the controller from the layout file.

Can anybody help?

To clarify - let's say I wanted to pass a variable titleto my layout.main, how would I do this? The method published above allows me to access only $arrayfrom the contents of 'index.blade.php

+5
source share
2 answers

To pass data to the layout, you use the first parameter as the name of the variable.

, :

$this->layout->nest('content', 'home.index', $array);

home.index, $array. , .

, , $content, , "nest".

API, , "", , : Laravel\View

with, .

, - :

$this->layout->with( 'myVariable' , $variable_to_pass_to_layout )
             ->nest('content', 'home.index', $array)
+7

-

View::share('myVariable', $variable_to_pass_to_layout);

, - .

0

All Articles