Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable undefined error in laravel blade view

Hey as i am passing a blade view which is having it own controller also i am including it into the view which does not have its own controller. it gives me an undefined variable error can any one help me how to it.

I have a view which does not have any controller only have Route like this Route::get('index', function () { return view('index'); }); in this view i am passing another view which having its own controller and also having some data from an array. but after using this view inside the view i get undefined variable error.

like image 879
Priyank lohan Avatar asked Sep 30 '16 10:09

Priyank lohan


1 Answers

Two steps :

  1. Declare & transfer $variable to View from Controller function.

     public function index()
     {
      return view("index", [ "variable" => $variable ]);
     }
    
  2. Indicate where transferred $variable from Controller appear in view.blade.php.

     {{ $variable }}
    

If you do not make sure, $variable is transferred or not

{{ isset($variable) ? $variable : '' }}
like image 73
m0z4rt Avatar answered Oct 10 '22 08:10

m0z4rt