title: Filter Eloquent morphTo relation based on column in other table
body: <p>I have an Eloquent model, that morphs to other Eloquent models, like this:</p>
  
  <pre><code>&lt;?php
  
  class Message extends Eloquent {
  
      public function message()
      {
          return $this-&gt;morphTo('message');
      }
  
  }
  </code></pre>
  
  <p>The reason being, the application has many different types of messages. I know it’s not the most elegant of approaches, but it’s what I’ve been lumbered with by the previous developer.</p>
  
  <p>So, my issue is: I need to only return <code>Message</code> instances, where the <code>state</code> column in the morphed-to message table matches a value. I have this query scope method in my <code>Message</code> model class:</p>
  
  <pre><code>public function scopeDeclinedMessages($query)
  {
      return $query-&gt;with(array('message' =&gt; function ($q)
      {
          $q-&gt;where('state', '=', MessageState::DECLINED);
  
      }));
  }
  </code></pre>
  
  <p>However, this doesn’t work, as it still returns <code>Messages</code> where the <code>state</code> in the morphed-to table <em>doesn’t</em> match the declined state. </p>
  
  <p>For transparency, <code>MessageState::DECLINED</code> is a value of <code>2</code>, but I’m getting messages back where the morphed-to table <code>state</code> column equals <code>0</code>.</p>