Is it possible to have a HasManyThrough relationship that's deeper than two levels?

后端 未结 2 1973
日久生厌
日久生厌 2021-01-20 00:54

I have the following models:

Product
BaseProduct
BaseCode
Series

Each of them is something of a separate entity, but they\'re related.

2条回答
  •  独厮守ぢ
    2021-01-20 01:42

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

    After the installation, you can use it like this:

    class Series extends Model {
        use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
    
        public function products() {
            return $this->hasManyDeep(Product::class,
                [BaseCode::class, BaseProduct::class],
                ['SeriesId', 'BaseCodeId', 'BaseProductId']
            );
        }
    }
    

提交回复
热议问题