title: Count from other table
body: <p>I am having problem to count number of devices where <code>guid</code> is not null.</p>
  
  <p>It need to get all the shops by user <code>user_id</code> and then count all the devices where <code>guid</code> is not null.</p>
  
  <pre><code>$shops = Shop::with('devices')-&gt;where('user_id', $userId)-&gt;get();
  
  $deviceActive = $shops-&gt;reduce(function ($carry, $item) {
       return $carry + $item-&gt;devices-&gt;whereNotNull('guid')-&gt;count();
  });
  
  dd($deviceActive );
  </code></pre>
  
  <p>It work when I do:</p>
  
  <pre><code>return $carry + $item-&gt;devices-&gt;count();
  </code></pre>
  
  <p>but it need to count where <code>guid</code> is not null.</p>
  
  <p>I would also be interested to hear if there is alternative <code>reduce</code> approach. </p>