How to use Laravel's hasManyThrough across 4 tables

后端 未结 3 477
栀梦
栀梦 2021-01-05 15:08

I have 4 tables with a structure and flow like this:

User
Accounts
Contacts
Orders

The relationship is as follows:

$user->hasMany(\

3条回答
  •  無奈伤痛
    2021-01-05 15:24

    you can through from user to contact then join with Orders

    public function orders(){
       return $this->hasManyThrough('Contact', 'Account', 'owner_id')->join('orders','contact.id','=','orders.contact_ID')->select('orders.*');
    }
    

    It works for me in same case, all feedback welcome

提交回复
热议问题