Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Laravel 4 Basics Laravel and Databases Eloquent ORM

Problem with Eloquent ORM

So this is code in TodoListController.php file

TodoListController.php
<?php
public function index(){
$todo_lists = TodoList::all();
return view('todos/index')->with('todo_lists', $todo_lists);
}
Routes.php
<?php
Route::get('/', 'TodoListController@index');
TodoList.php
<?php
class TodoList extends Eloquent{}

This is the output of DB::select('show tables;');

[{"Tables_in_odot":"migrations"},{"Tables_in_odot":"password_resets"},{"Tables_in_odot":"todo_lists"},{"Tables_in_odot":"users"}]

I have added two rows in todo_lists table manually with sequel pro

I'm wondering why it returns a blank page with no data. Could you help me please?

It seems stat TodoList::all() causes the problem but i can't understand why

3 Answers

What does your view 'todos/index' look like? Since you mentioned it is only a blank page, with no exceptions being thrown by Laravel, it seems to be finding everything that it is expecting to find.

Do you have something akin to:

<ul>
@foreach ($todo_lists as $list)
<li>{{$list->name}}</li>
@endforeach
</ul>

in your view?

I deleted php tags but still don't work

@extends('layouts.main')
@section('content')
    <h2>All Todo Lists</h2>
    <ul>
    <?php
    @foreach ($todo_lists as $list)
    <li>{{$list->name}}</li>
    @endforeach
    ?>
    </ul>
@stop

It seems that the problem is in $todo_lists = TodoList::all(); in TodoListController.php but i can't figure why

ok i solved. i made a mistake in the installation process.

Cool. Glad you figured it out.