我有两个名为contacts
and的表clients
。两个表都有group_id
作为外键。现在,当用户从表中找到一个组时,我想phone
从两个表中获取列值。我正在尝试这样的事情。但是得到空数组。有人能帮帮我吗!$request->groupid
groups
$getPhoneNumbers = Group::with(['hasContacts' => function($query){
$query->select('phone')->where('is_active', 1);
}])->with(['clients' => function($q){
$q->select('phone')->where('status', 1);
}])->where('id', $request->groupid)->get();
在组模型中 -
public function clients()
{
return $this->hasMany('App\Client', 'group_id', 'id');
}
public function hasContacts()
{
return $this->hasMany('App\Contact', 'group_id', 'id');
}