How to get the row count using Eloquent in Laravel?

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.

If you only want the count, then querying the count directly is much faster than fetching an entire collection and then getting the count.

// Query builder
$postCount = DB::table('posts')->where('user_id', '=', $user_id)->count();

// Eloquent
$postCount = Post::where('user_id', '=', $user_id)->count();