I have two tables:
- Users:
id, first_name, last_name, email
- Employees
id, user_id, wage
There has a relationship between users
and employees
. The problem comes from when I have a scope
inside the model:
public function scopeSearchPaginateAndOrder($query) {
$request = app()->make('request');
return $query->whereHas('user.internal_companies', function ($company) {
$company->where('companies.id', '=', \Session::get('current_company')['id']);
})->where(function ($query) use ($request) {
})->select(['user.first_name'])->get();
}
I am getting the following error:
Unknown column 'user.first_name' in 'field list
However, the relationship does exist:
public function user() {
return $this->belongsTo('App\User', 'user_id');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire