title: I need to count the number of images from each album
body: <p>I need to show the number of images that user's each album has. For that I assume I need another join or a subquery but I'm not being able to achive the result I want.</p>
  
  <pre><code>$userId = auth()-&gt;user()-&gt;id;
  $albums = DB::table('users_albums')
          -&gt;join('albums', 'users_albums.albumId', '=', 'albums.id')
          -&gt;where('users_albums.userId', $userId)
          -&gt;select('albums.name', 
              'albums.owner', 
              'albums.id', 
              'albums.created_at')
          -&gt;get();
  </code></pre>
  
  <p>Database structure:</p>
  
  <p><img src="https://i.stack.imgur.com/ND9eP.png" /></p>
  
  <p>EDIT:Added the following code and it worked. The issue now would be performance, but the main one is solved!</p>
  
  <pre><code>DB::raw('(SELECT 
      COUNT(I.id) 
  FROM 
      images I
  WHERE
      I.albumId = albums.id) as numberOfImages')
  </code></pre>