title: Laravel Eloquent belongsToMany and hasMany relationship query
body: <p>I'm using Laravel 4.2.8.</p>
  
  <p>I have two Eloquent models: <code>RapidsPacket</code> and <code>RapidsQuestion</code>. A <code>RapidsPacket</code> can contain any number of <code>RapidsQuestion</code> and a <code>RapidsQuestion</code> may be in any number of <code>RapidsPacket</code>.</p>
  
  <p>Here are my database tables:</p>
  
  <p>For the RapidsPacket model:</p>
  
  <pre><code>packets
   - id
   - name
  </code></pre>
  
  <p>For the RapidsQuestion model:</p>
  
  <pre><code>rapids
   - id
   - question
  </code></pre>
  
  <p>And the pivot table:</p>
  
  <pre><code>packet_rapid
   - id
   - packet_id
   - rapid_id
  </code></pre>
  
  <p>Here is the current skeleton of the models:</p>
  
  <pre><code>class RapidsPacket extends Eloquent {
  
      protected $table = 'packets';
  
      /**
       * Get this packet's questions
       *
       * @return RapidsQuestion
       */     
      public function questions()
      {
          return $this-&gt;belongsToMany('RapidsQuestion');
      }
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class RapidsQuestion extends Eloquent {
  
      protected $table = 'rapids';
  
      /**
       * Get this question's packets
       *
       * @return RapidsPacket
       */     
      public function packets()
      {
          return $this-&gt;belongsToMany('RapidsPackets');
      }
  
  }
  </code></pre>
  
  <p>What I want to be able to do is grab all questions in a packet, e.g:</p>
  
  <pre><code>$packet = RapidsPacket::find(2);
  $my_questions = $packet-&gt;questions()-&gt;get();
  </code></pre>
  
  <p>I also want to be able to get the packets, that a question might belong to. E.g:</p>
  
  <pre><code>$question = RapidsQuestion::find(30);
  $my_packets = $question-&gt;packets()-&gt;get();
  </code></pre>
  
  <p>If I try either of the above lines of code and <code>var_dump()</code> either <code>$my_questions</code> or <code>$my_packets</code> I get an enormous object containing all sorts of Laravel things but not the requested data.</p>
  
  <p>I have tried various iterations of passing different foreign and local keys to the <code>belongsToMany()</code> function but it never seems to return any models. This is driving me crazy. I've read countless answers on SO and the wider net about this problem but 5 hours down the line and I'm still no further. Please help!</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>Here is the contents of my database tables (v small):</p>
  
  <p><em>packets</em></p>
  
  <pre><code>id: 1
  name: test
  </code></pre>
  
  <p><em>rapids</em></p>
  
  <pre><code>id: 30
  question: 'sample 1'
  
  id: 40
  question: 'sample 2'
  
  id: 50
  question: 'sample 3'
  </code></pre>
  
  <p>_packet_rapid_</p>
  
  <pre><code>id: 1
  packet_id: 1
  rapid_id: 30
  
  id: 2
  packet_id: 1
  rapid_id: 40
  
  id: 3
  packet_id: 1
  rapid_id: 50
  </code></pre>
  
  <p><strong>Update 1:</strong></p>
  
  <p>Just changed RapidsPacket to <code>belongsToMany</code> rather than <code>hasMany</code> but still to no avail</p>