Level 122
with a subselect?
https://laraveldaily.com/post/laravel-eloquent-subquery-subselect-examples
or a second query
I have the following Eloquent:
$latestFivePosts = Post::query()
->join('users AS u', 'u.id', 'posts.user_id')
->where('user_id', auth()->id())
->latest('posts.created_at')
->take(5)
->get();
I want to get the total count of posts for that user too. I know COUNT is an aggregate function and returns one query.
Is there an alternative way to run the same query with some modifications?
$posts = Post::query()
->join('users AS u', 'u.id', 'posts.user_id')
->where('user_id', auth()->id())
->count();
Please or to participate in this conversation.