2

Week 4 of 100DaysOfCode Laravel Challenge

 2 years ago
source link: https://dev.to/arifiqbal/week-4-of-100daysofcode-laravel-challenge-go9
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Weekly 100DaysOfCode Laravel (4 Part Series)

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.
  • 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.
  • 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.
  • 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.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK