Php Laravel中的约束关系
也许你能帮我解决我现在的问题 我有Php Laravel中的约束关系,php,mysql,laravel,laravel-7,Php,Mysql,Laravel,Laravel 7,也许你能帮我解决我现在的问题 我有产品那有很多关系 /** Inherits from : category, subcategory and model */ Product->hasMany(CategoryAttributes, $this->category) Product->hasMany(SubCategoryAttributes, $this->subCategory) Product->hasMany(ModelAttributes, $this-
产品
那有很多关系
/** Inherits from : category, subcategory and model */
Product->hasMany(CategoryAttributes, $this->category)
Product->hasMany(SubCategoryAttributes, $this->subCategory)
Product->hasMany(ModelAttributes, $this->model)
/** */
Product->hasMany(HideForSubcategoryAttributes, $this->subCategory)
Product->hasMany(IgnoreForModelAttributes, $this->model)
现在我需要实现一些东西,为我提供产品的所有属性
产品的这些属性应该是动态的。此外,它应该以某种方式优化性能和节省内存,因为我可以获得超过10k的产品,大约1k个型号,100个子类别和类别
Product.php
class Product extends Model
{
public $fillable = [
'model_id',
'subcategory_id',
'category_id',
];
/**
* @return HasMany
*/
public function categoryAttributes(): HasMany
{
return $this->hasMany(
CategoryAttributes::class,
'category_id',
'category_id'
);
}
/**
* @return HasMany
*/
public function hideSubcategoryAttributes(): HasMany
{
return $this->hasMany(
HideForSubcategoryAttributes::class,
'subcategory_id',
'subcategory_id'
);
}
/**
* @return HasMany
*/
public function subcategoryAttributes(): HasMany
{
return $this->hasMany(
SubcategoryAttributes::class,
'subcategory_id',
'subcategory_id'
);
}
/**
* @return HasMany
*/
public function ignoreForModelAttributes(): HasMany
{
return $this->hasMany(
ModelIgnore::class,
'model_id',
'model_id'
);
}
/**
* @return HasMany
*/
public function modelAttributes(): HasMany
{
return $this->hasMany(
ModelAttribute::class,
'model_id',
'model_id'
);
}
}
Category.php、subcategory attributes.php、modeldattributes.php、HideForSubcategoryAttributes.php、ModelIgnore.php都有以下关系:
public function attribute(): HasOne
{
return $this->hasOne(Attribute::class, 'id', 'attribute_id');
}
在某个地方,我希望所有属性都是有效的(不被忽略和隐藏),因此我需要以下各项的总和:
(类别+子类别属性+模型属性)-(HideForSubcategoryAttributes+ModelIgnore)=验证产品属性问题不清楚,请提供模型详细信息/代码。