How can I get the number of rows using Eloquent? Suppose I want to count all posts created by one user.
I know I can count the result I get from the query but this is not an efficient way, is it?
$posts = DB::table('posts')->where('user_id', '=', $user_id)->get();
$postCount = count( $posts );
It could be 1000 posts and I don’t want to fetch them and then count them. There should be a better way to count rows in Laravel.