title: Optimize query with Eloquent (count on big table)
body: <p>I have an administration panel and in it I display all the users, with a line that mentions how many photos he has posted.</p>
  <p>By default I have a seeder that imports 17,000 photos and the user who posts them is an administrator, so I have 1 user who has 17,000 photos.</p>
  <p>In this panel, I display this count:</p>
  <pre><code>{{ $user-&gt;pictures()-&gt;count() }}
  </code></pre>
  <p>However with the debug bar I see that it takes a lot of time (300ms), here is the query with the debug bar:</p>
  <pre><code>select count(*) as aggregate from `pictures` where `pictures`.`user_id` = 'fe9eaf79-fc2d-47b8-8a43-4c61a81bce22' and `pictures`.`user_id` is not null and `status` = 1 and `pictures`.`deleted_at` is null
  </code></pre>
  <p>In the controller, I've this :</p>
  <pre><code>public function show()
      {
          $users = User::orderBy('username', 'ASC')
              -&gt;paginate(20);
  
          return view('admin.users', [
              'users' =&gt; $users,
          ]);
      }
  </code></pre>
  <p>Do you know how I can optimize this count on such a big table?</p>