I am trying to send a variable to a file blade view, but will skip this error:
Undefined variable: data (View: D: \ wamp \ www \ tienda \ resources \ views \ cliente.blade.php)
This is my route:
Route::resource('cliente','ClienteController');
This is my client controller:
public function index(){ $data = Cliente::all(); return view('cliente',compact($data)); }
And my blade:
@foreach ($data as $user) <tr> <td>{{$user->nombre}}</td> </tr> @endforeach
What am I doing wrong?
Also, if you try to do this, for example, this is the Cliente Controller:
public function index(){ return view('cliente', ['name' => 'James']); }
And the blade:
{{$name}}
That yes works ... Only variables and arrays do not work.
source share