I have two tables named contacts and clients. Both tables have group_id as foreign_key. Now, I want to get phonecolumn value from both tables when user $request->groupid will found a group from groupstable. I am trying something like this. But getting empty array. Would someone help me please!
$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();
In Group model -
public function clients()
{
return $this->hasMany('App\Client', 'group_id', 'id');
}
public function hasContacts()
{
return $this->hasMany('App\Contact', 'group_id', 'id');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire