Column not found - Laravel whereHas error
<p>I'm having a hard time resolving this error.</p>

<p>My models:</p>

<p>User Model:</p>

<pre><code>class User extends Model{
    public function requests()
    {
        return $this-&gt;hasMany('App\Models\TeamRequest','requested_user_id');
    }
}
</code></pre>

<p>TeamRequest Model:</p>

<pre><code>class TeamRequest extends Model {

    public function requested_user()
    {
        return $this-&gt;belongsTo('App\Models\User', 'requested_user_id');
    }
}
</code></pre>

<p>Now, I am trying this query:</p>

<pre><code>UserModel::whereHas('requests',function($query) use ($team_id){
            $query-&gt;where('team_id',$team_id)
                    -&gt;get();
        });
</code></pre>

<p>And, I'm getting an error:</p>

<blockquote>
  <p>Column not found: 1054 Unknown column 'users.id' in 'where clause'
  (SQL: select count(*) from <code>team_requests</code> where
  <code>team_requests</code>.<code>requested_user_id</code> = <code>users</code>.<code>id</code>)</p>
</blockquote>

<p>Why am I getting this error?</p>

<p>Schema:</p>

<p>users table</p>

<p>primary key - id</p>

<p>varchar - email</p>

<p>varchar - password</p>

<p>team_requests table</p>

<p>primary key - id</p>

<p>integer - requested_user_id</p>

<p>I have other columns but I believe they do are not of effect.</p>