Laravel 5 Querying with relations causes "Call to a member function addEagerConstraints() on null" error
You are missing return statements in the methods that define relations. They need to return relation definition.
Replace
public function roles()
{
$this->belongsToMany('\App\Role', 'fk_user_role', 'user_id', 'role_id');
}
With
public function roles()
{
return $this->belongsToMany('\App\Role', 'role_user', 'user_id', 'role_id');
}
You forgot the return in your functions
Do:
return $this->belongsToMany('\App\User', 'fk_role_user', 'role_id', 'user_id');
return $this->belongsToMany('\App\Role', 'fk_user_role', 'user_id', 'role_id');