這裏是我的代碼:Laravel 5.3關係
class Company extends Model {
public function employees() {
return $this->hasMany('Employee');
}
}
class Employee extends Model{
protected $table = "user_role_company";
public function user(){
return $this->belongsTo('User');
}
public function company(){
return $this->belongsTo('Company');
}
}
class User extends Authenticatable {
public function employee(){
return $this->hasMany('Employee');
}
}
如果我運行:
$recordsTotal = User::with(['employee' => function ($query) use ($company_id) {
$query->where('company_id', $company_id);
}])->count();
它返回所有的用戶數不僅empolyee計數。
我在做什麼錯?
感謝
您的查詢工作!謝謝!! – user3844579