· August 20, 2020 · ⋆ Laravel There comes a time when you want to fetch the number of records for a child relationship along with the main Eloquent query. For instance, let’s say, I want to get the number of books and publications when fetching authors.
You can use alias (using as) and Closures to utilize the same relationship twice in withCount for different constraints like so.
Follow me on Twitter @amit_merchant Define relationships outside of Eloquent models in Laravel How to detect fullscreen mode using CSS Fetch count of records for children relationships in Laravel Eloquent The difference between for...in & for...of in JavaScript Insert mass database records using model factories in Laravel