06 - With() VS WithCount(): Out of RAM Memory?
We found 7 results for "withCount".
Let's look at a scenario where you must query the related records amount. A typical example would be loading the user with projects, and you need to show the amount of projects per user
Quite often web-developers don't care enough about errors. If something goes wrong, you often see default Laravel texts like "Whoops, something went wrong" or, even worse, the exception code, which is not helpful at all to the visitor. So I decided to write a step-by-step article of how to handle errors in elegant way and present proper error information to the visitor.
The performance of our applications is one of the top things we should care about. Inefficient Eloquent or DB queries are probably no.1 reason for bad performance. In this tutorial, I will show you the top 3 mistakes developers make when it comes to Eloquent performance, and how to fix them.
Eloquent has one less-known function called withCount(): it helps to get the amount of related records inside of the main object. It also works with two layers deep, inside of hasManyThrough relations. Let's take a look.
Another *practical* video of helping someone on Laracasts forum to query the data. This video has a "plot twist" where I decided to make my code even better.
To calculate the related records, we use withCount() in Eloquent. But there are a few "advanced" features I want to show you today.