I have two tables named contacts
and clients
. Both tables have group_id
as foreign_key. Now, I want to get phone
column value from both tables when user $request->groupid
will found a group from groups
table. 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');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XiO0QL
via IFTTT
Aucun commentaire:
Enregistrer un commentaire