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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners