title: Better approach for nested query
body: <p>I am very new in Laravel.</p>
  
  <p>I have this query</p>
  
  <pre><code>$city = City::where('slug', $slug)-&gt;first();
  $city-&gt;users = $city-&gt;users()-&gt;where('gender', 'male')-&gt;get();
  </code></pre>
  
  <p>So I am wondering what is a better approach for this situation. To sum up, I need to find a city and all users belonging to the city where gender = male.</p>
  
  <p>I've tried to do this but didn't work</p>
  
  <pre><code>$city = City::whereHas('users', function($q) {
              $q-&gt;where('gender', '=', 'male');
          })-&gt;where('slug', $slug)
            -&gt;first();
  </code></pre>
  
  <p>What I am missing?</p>