mercredi 16 décembre 2020

Laravel hasOne relationship where condition same table field

I have 5 tables retailers, doctors, softwareproviders, members and contactpersons. contactpersons table associated with other 4 tables using type and refid.

retailers

id name contactno mem_type
2 karthik 855550 1

members

id name contactno
6 naveen 855550

contactpersons

id type refid name
1 1 2 ruban
1 2 6 aron

type 1 - retailers, 2 - members, 3 - doctors, 4 - softwareproviders

In contactpersons model how to make hasone relationship with other tables

public function retailersinfo(){

  return $this->hasOne('App\Retailers','id','refid');
}

we need to add type condition (where condition =1).



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire