Eloquent - dig deeper

If you're looking for an intro to Eloquent, you won't find it here. Instead, I'll try to illustrate some real problems I've run into regarding Eloquent, and databases in general.

You'll find these things in the Eloquent documentation, but you have to look for them, otherwise they're easy to miss. Especially when you're starting and everything is easy and just works. It's power is limitless, you can do pretty much any queries you can think of. There are a few things to be wary of though.

1. n+1

This is not really related to Eloquent, but to databases in general. Whenever you are working with multiple rows of one or more tables, you can easily run into this issue. And it’s a sneaky one, if you’re not careful.

To me, it feels weird that this issue is often skipped in favor of learning the correct syntax of select or update or any other semi-important, muscle memory exercised con...

25 mins read

2. Fine-grain-ing

After spending a considerable amount of time looking for the worst title I could give this article, I settled on this one. In this one I’ll try to draw your attention to the second caveat of Eloquent’s deceiving playfulness: unnecessary load of columns from the database.

And yes, I had to learn this the hard way. When you have a few queries per second, and your tables consist of hundred...

15 mins read