title: Count a Model based on another Model with many-to-many relation
body: <p>Here's my task:</p>
  <pre class="lang-php prettyprint-override"><code>class Task extends Model
  {
      public function parts()
      {
          return $this
              -&gt;belongsToMany(Part::class)
              -&gt;withPivot('count');
      }
  }
  </code></pre>
  <p>Using Eloquent, how I can check how many parts were used for tasks that have end date between X and Y? I want to list all parts at the same time, as there's only several types</p>
  <p>By far I got this:</p>
  <pre class="lang-php prettyprint-override"><code>collect(
      ProjectTask::with('parts')
          -&gt;has('parts')
          -&gt;where('end_date', '&gt;=', $now)
          -&gt;where('end_date', '&lt;=', $to)
          -&gt;get()
  )
  </code></pre>
  <p>but have no idea what to do next</p>