Eloquent, the ORM native to Laravel can be powerful when used in the right hands. However, if you’re unaware of how things work beneath the hood you may, at times, find yourself struggling. I’m often asked questions related to how eager loading works, and selecting columns when using eager loading seems to raise a common issue.
Consider the following: When selecting columns and using eager loading (via the ‘with’ method) you may find that your query returns 0 results, regardless of whether relations exist or not. This may seem confusing at first, but when you understand how eloquent implements eager loading, it begins to make sense. Read more →