title: How to eager load only 1 result from many to many relationship Laravel
body: <p>How can I eager load only one from many to many relationship?</p>
  
  <p>I have two models <code>Application</code> &amp; <code>Applicant</code></p>
  
  <p><code>Models\Application.php</code></p>
  
  <pre><code>public function applicants() {
      return $this-&gt;belongsToMany(Applicant::class);
  }
  
  public function oneApplicant() {
      return $this-&gt;applicants()-&gt;first();
  }
  </code></pre>
  
  <p>I'm wanted to paginate on the applications and want to load only one applicant (if they have.)</p>
  
  <pre><code>return Application::stage( $stages )
  -&gt;stagenot($stageNot)
  -&gt;refered( $refered, $term )
  -&gt;with(['oneApplicant'])
  -&gt;orderBy('created_at','desc')-&gt;paginate( $count );
  </code></pre>
  
  <p>But it isn't working.
  Getting the first result like this <code>return $this-&gt;applicants()-&gt;first()</code>
  will produce an error <code>Call to undefined method Illuminate\Database\Query\Builder::with()</code></p>
  
  <p>If I also put a limit instead of first <code>return $this-&gt;applicants()-&gt;limit(1)</code> it will only show one applicant to the last collection.</p>
  
  <p>I also tried to modify the query directly on eager loading call to get the first row</p>
  
  <pre><code>return Application::with(['applicants',  =&gt; function( $query ) {
          $q-&gt;first();
      }])-&gt;orderBy('created_at','desc')-&gt;paginate( $count );
  </code></pre>
  
  <p>But the result is the same as adding a <code>limit(1)</code> on directly on the relation, it will only add one applicant to the last item from collection and the other item have empty array value </p>
  
  <p>Can anybody help :)</p>
  
  <p>Thanks</p>