I already read doc here : https://github.com/laravel/framework/pull/25997
What i want to know is by using withCount()
we were just load count of records instead of getting all relations data.
So by using loadCount()
what we can do ?
Please explain in short in simple words. Thanks
loadCount Eloquent Collection Method introduced by the release of Laravel 5.7.10. According to the laravel-news.
loadCount is the ability to load relationship counts on an Eloquent collection. Before this feature, you could only load relationships, but now you can call loadCount() to get counts for all relations.
The pull request illustrates how you could use loadCount() with the following example:
$events = Event::latest()->with('eventable')->paginate();
$groups = $events->map(function ($event) {
return $event->eventable;
})->groupBy(function ($eventable) {
return get_class($eventable);
});
$groups[Post::class]->loadCount('comments');
$groups[Comment::class]->loadCount('hearts');
return new EventIndexResponse($events);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With