This week I had a chance to discover more about Laravel's Eloquent Model. I learned many concepts including Route-Model binding, Eloquent relationships (used belongsTo()
and hasMany()
out of the available) relationships, the N+1
problem, debugging Laravel using Log
façade or the Clockwork
package.
Below is a recap of my week in the form of separate posts.
- Laravel's route model binding feature allows us to bind a route wildcard to an Eloquent model instance.
Route Model binding in Laravel
Arif Iqbal ・ Dec 14 ・ 2 min read
- Our next job is to figure out how to assign a category to each post. To allow for this, we'll need to create a new Eloquent model and migration to represent a
Category
.
Your First Eloquent Relationship in Laravel
Arif Iqbal ・ Dec 19 ・ 3 min read
- Now that we have the concept of a
Category
in our application, let's make a new route that fetches and loads all posts that are associated with the given category.
Show All Posts Associated With a Category in Laravel
Arif Iqbal ・ Dec 19 ・ 2 min read
- We introduced a subtle performance issue in the last episode that's known as the N+1 problem. Because Laravel lazy-loads relationships, this means you can potentially fall into a trap where an additional SQL query is executed for every item within a loop. Fifty items...fifty SQL queries. In this episode, we debug these queries - both manually, and with the excellent Clockwork extension - and then we solve the problem by eager loading any relationships we'll be referencing.
Oldest comments (0)