Laravel: how to pass a variable to my basic layout -


i trying pass variable basic layout. because need in pages. thought writing on basecontroller

protected function setuplayout() {     if ( ! is_null($this->layout))     {         $footertext = mytext::where('status', 1);         $this->layout = view::make($this->layout, ['footertext' =>$footertext ]);         }     } } 

and on thought writing on main.blade.php work.

 {{ $footertext }}. 

instead having error,

undefined variable: footertext

and after 2 hours of looking around...i didn't find solution. welcome.

not long ago trying same.

if using laravel 5 can edit appserviceprovider.php inside app/providers , register provider layout like:

public function boot() {   view()->composer('my.layout', function($view) {     $myvar = 'test';     $view->with('data', array('myvar' => $myvar));   }); } 

now if using laravel 4 think it's more simple. in app/filters.php:

view::composer('my.layout', function ($view) {   $view->with('variable', $variable); }); 

in both ways variable pass available templates extending master template.

references:

https://laracasts.com/discuss/channels/general-discussion/laravel-5-pass-variables-to-master-template https://coderwall.com/p/kqxdug/share-a-variable-across-views-in-laravel?p=1&q=author%3aeuantor


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -