title: Eloquent Query for "BelongsToMany" Relationship
body: <p>When I want to query for all states a specific dispatch ticket in my database, I would do it like this:</p>
  
  <pre><code>public function test() {
      $dispatches = Dispatch::where('dispatch_reference', '=', 'dis_548k14s4glnhv5')-&gt;get();
      foreach($dispatches-&gt;states as $state) {
          var_dump($state);
      }
  }
  </code></pre>
  
  <p>But this throws an error message, that <code>states</code> is not being recognized. The models I created are:</p>
  
  <p><strong>Dispatch</strong></p>
  
  <pre><code>class Dispatch extends Model {
  
      use EventGenerator;
  
      protected $table = 'dispatches';
      protected $fillable = ['dispatch_reference', 'incident_reference', 'state'];
      public $timestamps = true;
  
      // Since the FK exists in this table, the belongsTo() method is used to state that the dispatch model is related to an address.
      // Dispatch __belongs_to__ Incident
      public function incident() {
          return $this-&gt;belongsTo('App\Classes\Incident');
      }
  
      // Dispatch __belongs_to_many__ State
      public function states() {
          return $this-&gt;belongsToMany('App\Classes\DispatchState')-&gt;withTimestamps();
      }
  
      public function attachDispatchState($id) {
          $this-&gt;states()-&gt;attach($id);
          $this-&gt;touch();
      }
  
      // set fields on the eloquent object and save to database
      // raise event that the incident was created.
      public function createDispatch($command) {
  
          // Get BodyContent from POST Request
          $this-&gt;dispatchReference = $command-&gt;dispatchReference;
          $this-&gt;incidentReference = $command-&gt;incidentReference;
  
          // Create new Dispatch
          $dispatch = Dispatch::create(array(
              'dispatch_reference' =&gt; $this-&gt;dispatchReference,
              'incident_reference' =&gt; $this-&gt;incidentReference
          ));
          $dispatchState = DispatchState::where('state', '=', 'processing')-&gt;first();
          $dispatch-&gt;attachDispatchState($dispatchState-&gt;id);
  
          return $this;
      }
  </code></pre>
  
  <p><strong>Dispatch State</strong></p>
  
  <pre><code>class DispatchState extends Model {
  
      use EventGenerator;
  
      // Define Table Setup with fillabe fields
      protected $table = 'dispatch_states';
  
      // Fillable fields in database
      protected $fillable = ['state'];
  
      // include timestamps
      public $timestamps = true;
  
      // Status __belongs_to_many__ Dispatches
      public function dispatches() {
          return $this-&gt;belongsToMany('App\Classes\Dispatch');
      }
  }
  </code></pre>
  
  <p>I would expect to see all the different states attached to one dispatch as i am using a pivot table that works fine so far. I just cannot query the results. Do I have an error in my models?</p>