Category: Laravel, PHP, javascript

· 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
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners