title: Laravel Query builder in many to many Relationship
body: <p>Let's consider that I have a model called <code>Sportman</code> and another one <code>Sport</code> who are linked via a <code>pivot</code> table : <strong>many to many</strong> relationship.</p>
  
  <p>A sample code for their migrations.</p>
  
  <pre><code># Sportmans migration
  Schema::create('sportsmans', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('firstname');
      $table-&gt;string('lastname');
  });
  
  # Sports migration
  Schema::create('sports', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('name');
      $table-&gt;string('description');
  });
  </code></pre>
  
  <p>Here is their relationship in models :</p>
  
  <pre><code># Defining association in Sportsman model
  public function sports(){
      return $this-&gt;belongsToMany( Sport::class, 'sportsman_has_sports', 'person_id', 'sport_id' );
  }
  
  # Defining association in Sports model
  public function sportsman(){
      return $this-&gt;belongsToMany( Sportsman::class );
  }
  </code></pre>
  
  <p>How can I using Laravel with Eloquent get the <code>sportsman</code> that play:</p>
  
  <ol>
  <li>Only "Footbal"</li>
  <li><em>Box</em> or "Swimming"</li>
  <li><strong>Both "Tennis and <em>Basket-ball</em></strong></li>
  </ol>
  
  <p>Here is what I tried to do for question 2 :</p>
  
  <pre><code>Sportsman::with(['sports:person_id,id,name'-&gt;whereHas('sports', function ($query) {
      $query-&gt;whereIn('name', ['Box', 'Swimming'] );
  });
  </code></pre>
  
  <p>Most difficult is the <strong>question 3</strong></p>