Reputation: 1
I am new to laravel. I am facing error while i fetch the data from database. But other pages are working (fetching also).
Here is My code for your review. my contorller :
public function info()
{
// Show the page
$data = Customer::all();
return view('eventlist')->with('data',$data);
}
My view :eventlist.blade.php
<tbody>
@foreach ($events as $user)
<tr>
<td>{!! $user->name !!}</td>
<td>{!! $user->cname !!}</td>
<td>{!! $user->sdate !!}</td>
<td>{!! $user->edate !!}</td>
<td>{!! $user->room !!}</td> </tr>@endforeach
</tbody>
My route :
Route::get('eventlist', 'MyController@info');`
While i try to fetch the data : It shows the error undefined variable :events
Help me to solve this issue. Thanks in advance
Upvotes: 0
Views: 21
Reputation: 5135
You are looping for wrong variable, look at your this line
@foreach ($events as $user)
you are looping $events
and from controller
you are passing data
variable. see your this line
return view('eventlist')->with('data',$data);
so change your this line
@foreach ($events as $user)
to this
@foreach ($data as $user)
everything will be fine
Upvotes: 2