我有三个模型:ProductType、ProductSubtype 和 ProductSubtypeCategory
产品类型.php
class ProductType extends Model{
// A product type has many subtypes
public function product_subtypes(){
return $this->hasMany(ProductSubtype::class);
}
}
产品子类型.php
class ProductSubtype extends Model{
// Each product subtype belongs to a type
public function product_type(){
return $this->belongsTo(ProductType::class);
}
// A product subtype has many categories
public function product_subtype_categories(){
return $this->hasMany(ProductSubtypeCategory::class);
}
}
产品子类型类别.php
class ProductSubtypeCategory extends Model{
// Each cateogory belongs to a subtype
public function product_subtype(){
return $this->belongsTo(ProductSubtype::class);
}
}
我只想要其中存在产品子类型和子类型类别的产品类型。到目前为止我已经尝试过这个
return ProductType::has('product_subtypes', function ($query){
$query->has('product_subtype_categories');
})->get();
有没有任何官方方法可以从这种嵌套关系中获得我想要的结果?
qq_遁去的一_1