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

Databases

laravel 5 uses Model rather than Eloquent

hope this is in the correct place... discussion on laravel 4 basics, eloquent ORM.

when using laravel 5, I had to extend the TodoList class using model, then things (mostly) worked. The other caveat was that I had to use \App\TodoList::all(); in the TodoListController.php.

my TodoList.php:

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class TodoList extends Model {}

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Leo,

As the Laravel course here on Treehouse is catering only for Laravel 4, it should be noted that not everything is the same as Laravel 5 did bring in some large changes that differ from the previous major version, that being version 4.

when using laravel 5, I had to extend the TodoList class using model, then things (mostly) worked.

Extending Modal instead of Eloquent is how relationships are created to the database now, lots of core changes were made to simplify yet significantly improve on this area which removes from redundancy and improves on performance. You can read more about Eloquent models in Laravel 5 at the below link.

https://laravel.com/docs/5.2/eloquent#defining-models

The other caveat was that I had to use \App\TodoList::all(); in the TodoListController.php.

This change was for the better, Laravel 5.0 moved the entire application layer into a single App namespace to improve visibility and maintainability of the code base. It will take some time to get used to, but this approach is the correct way of writing modular code in PHP.

All that said, your code from Laravel 4 won't work 100%, you will need to make changes based on the Laravel 5 documentation which has all the information needed to make an annoying upgrade an easy one.

https://laravel.com/docs/5.2

Hope that helps.