0

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.