withCount is a new method of laravel to return count of the relations. I'm trying to use with and withCount together. For example:
Article::with('Comments')->withCount('Comments')->paginate();
Problem I'm facing is, in the results is see for example:
comments_count = 10
comments = []
It returns comments array null. I don't know is it possible to get both the results or not. In some articles on different sites, i see withCount still has some restrictions. But not sure what I'm trying to do is possible or not.
Please help me to know about this issue.
Thank you,
No Need to write with.
Article::withCount('Comments')->paginate();
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