How to use Laravel's hasManyThrough across 4 tables

后端 未结 3 485
栀梦
栀梦 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:25

    I created a HasManyThrough relationship with unlimited levels: Repository on GitHub

    After the installation, you can use it like this:

    class User extends Model {
        use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
    
        public function orders() {
            return $this->hasManyDeep(Order::class, [Account::class, Contact::class]);
        }
    }
    

提交回复
热议问题