Ahmed Karmous
Ahmed Karmous

Reputation: 373

laravel 4.1 fill table with data from data base

I'm trying to fill atable with data from my data base ive done that with laravel 4.2 but in 4.1 it won't work the error is

Undefined variable: questions (View: C:\wamp\www\happy_Road\app\views\home\home.blade.php)

this is the view

<div class="col-md-12">
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
            <th>Thémathique</th>
            <th>Question</th>
            <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        @foreach ($questions as $question)
        <tr>
        <td>{{ $question->theme }}</td>
        <td>{{ $question->question }}</td>

        <td >
        </td>

        </tr>
        @endforeach
        </tbody>
        <tfoot></tfoot>
        </table>
        {{  $questions->links(); }}
</div>  

this is the controller

public function index()
{
        if (Auth::check())
        {
            $questions = questionList::paginate(10);
            return View::make('home.home')->with('user',Auth::user());
        }
        else
        {
            return Redirect::to('login')->with('message',"Vous devez vous connecter d'abord");
        }

}

what is wrong with this method !! any help please ! thx :)

Upvotes: 1

Views: 820

Answers (1)

Mark Baker
Mark Baker

Reputation: 212412

Pass questions through to your view

return View::make('home.home')
    ->with('questions', $questions)
    ->with('user', Auth::user());

Upvotes: 3

Related Questions