Presentation - Eloquent ORM

Posted by Andy Huggins on April 22, 2016

I am going to try to record a screencast version of this presentation, and once I get that done, I will post the video here as well.

For now, here is the link to the slides:

The reason I put together this presentation is I find that Eloquent is one of the more powerful parts of Laravel. Part of that could be the fact that most applications that people work on tend to be database driven, but I think Eloquent provides a lot of helpful methods that go beyond the minimum that would be required to allow easy use of the data from the database.

The thing that blew my mind with Eloquent is Relationships. Being able to define the relationships on your model, and easily access the related model. Just BOOM. Especially when you get into the polymorphic relations. Granted at the time, polymorphism in general was an idea I was struggling to really understand, but after seeing how Eloquent handled them, it made them more accessible.

Then throw in things like Accessors and Mutators, being able to cast data to specific types when you are accessing them (like the created_at and updated_at fields (which Eloquent automatically handles for you) are returned as an instance of Carbon) makes the data a breeze to work with.

These (little) details are what make Eloquent a joy to use, and ultimately that is what I was intending to share with the group who may not be using Laravel/Eloquent.

The presentation kind of skips Migrations, which are important, but the talk was to be focused on Eloquent and I felt I would have to gloss over Migrations so fast that it would just be more confusing. As it turns out, it might have been better to add a slide or two or at least mention which fields were assumed to be in the database for a few of the examples. But hey, it's the second presentation I have ever given.

Additionally, I learned in the making and presenting of this, that you should focus talks on much smaller pieces. Eloquent has so many features trying to give a solid overview of everything in 30 minutes is pretty tricky.