How to setup conditional relationship on Eloquent : <p>I have this (simplified) table structure:</p>

<pre><code>users
- id
- type (institutions or agents)

institutions_profile
- id
- user_id
- name

agents_profile
- id
- user_id
- name
</code></pre>

<p>And I need to create a <code>profile</code> relationship on the <code>Users</code> model, but the following doesn't work:</p>

<pre><code>class User extends Model
{
    public function profile()
    {
        if ($this-&gt;$type === 'agents')
            return $this-&gt;hasOne('AgentProfile');
        else
            return $this-&gt;hasOne('InstitutionProfile');
    }    
}
</code></pre>

<p>How could I achieve something like that?</p>
