Php 如何使laravel中的整个对象具有多个表?(数据库结构更新)
产品型号Php 如何使laravel中的整个对象具有多个表?(数据库结构更新),php,laravel,eloquent,Php,Laravel,Eloquent,产品型号 protected $fillable = ['name','brand_id','sort']; public function brands() { return $this->belongsTo('App\Brands','brand_id'); } public function sub_attributes() { return $this->hasMany('App\SubAttributes','id'); } public function
protected $fillable = ['name','brand_id','sort'];
public function brands() {
return $this->belongsTo('App\Brands','brand_id');
}
public function sub_attributes() {
return $this->hasMany('App\SubAttributes','id');
}
public function values() {
return $this->hasMany('App\AttributesValue','product_id');
}
protected $fillable = ['name'];
public function product() {
return $this->belongsTo('App\Product');
}
public function sub_attribute() {
return $this->hasMany('App\SubAttributes','main_attribute_id');
}
public function attributes_value() {
return $this->hasManyThrough('App\AttributesValue','App\SubAttributes');
}
protected $fillable = ['name','main_attribute_id','filter'];
public function main_attribute() {
return $this->belongsTo('App\MainAttributes','main_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','product_id');
}
public function attribute() {
return $this->hasMany('App\AttributesValue','sub_attribute_id');
}
public function sub_attribute() {
return $this->belongsTo('App\SubAttributes','sub_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','id','product_id');
}
主属性模型
protected $fillable = ['name','brand_id','sort'];
public function brands() {
return $this->belongsTo('App\Brands','brand_id');
}
public function sub_attributes() {
return $this->hasMany('App\SubAttributes','id');
}
public function values() {
return $this->hasMany('App\AttributesValue','product_id');
}
protected $fillable = ['name'];
public function product() {
return $this->belongsTo('App\Product');
}
public function sub_attribute() {
return $this->hasMany('App\SubAttributes','main_attribute_id');
}
public function attributes_value() {
return $this->hasManyThrough('App\AttributesValue','App\SubAttributes');
}
protected $fillable = ['name','main_attribute_id','filter'];
public function main_attribute() {
return $this->belongsTo('App\MainAttributes','main_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','product_id');
}
public function attribute() {
return $this->hasMany('App\AttributesValue','sub_attribute_id');
}
public function sub_attribute() {
return $this->belongsTo('App\SubAttributes','sub_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','id','product_id');
}
子属性模型
protected $fillable = ['name','brand_id','sort'];
public function brands() {
return $this->belongsTo('App\Brands','brand_id');
}
public function sub_attributes() {
return $this->hasMany('App\SubAttributes','id');
}
public function values() {
return $this->hasMany('App\AttributesValue','product_id');
}
protected $fillable = ['name'];
public function product() {
return $this->belongsTo('App\Product');
}
public function sub_attribute() {
return $this->hasMany('App\SubAttributes','main_attribute_id');
}
public function attributes_value() {
return $this->hasManyThrough('App\AttributesValue','App\SubAttributes');
}
protected $fillable = ['name','main_attribute_id','filter'];
public function main_attribute() {
return $this->belongsTo('App\MainAttributes','main_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','product_id');
}
public function attribute() {
return $this->hasMany('App\AttributesValue','sub_attribute_id');
}
public function sub_attribute() {
return $this->belongsTo('App\SubAttributes','sub_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','id','product_id');
}
属性值模型
protected $fillable = ['name','brand_id','sort'];
public function brands() {
return $this->belongsTo('App\Brands','brand_id');
}
public function sub_attributes() {
return $this->hasMany('App\SubAttributes','id');
}
public function values() {
return $this->hasMany('App\AttributesValue','product_id');
}
protected $fillable = ['name'];
public function product() {
return $this->belongsTo('App\Product');
}
public function sub_attribute() {
return $this->hasMany('App\SubAttributes','main_attribute_id');
}
public function attributes_value() {
return $this->hasManyThrough('App\AttributesValue','App\SubAttributes');
}
protected $fillable = ['name','main_attribute_id','filter'];
public function main_attribute() {
return $this->belongsTo('App\MainAttributes','main_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','product_id');
}
public function attribute() {
return $this->hasMany('App\AttributesValue','sub_attribute_id');
}
public function sub_attribute() {
return $this->belongsTo('App\SubAttributes','sub_attribute_id');
}
public function product() {
return $this->belongsTo('App\Product','id','product_id');
}
数据库结构:-
表:产品
身份证、姓名、品牌号
表:主属性
身份证,姓名
表:sub_属性
id、名称、主属性\u id
表:属性值
id、产品id、子属性id、值
我需要按产品id的值数组
数组[产品[
id:10
名称:产品名称
品牌:产品品牌
主属性:[
id:1
名称:产品主属性
子属性:[
id:5
名称:主属性有子属性
主属性标识:1
值:[
id:id
产品编号:10
子属性id:5
值:一些文本
]
]
]
]
] 我想通过产品id->主属性->子属性->属性值获取 我得到的只是值,但现在整个对象是连续的,所以请尽快回复
提前谢谢请添加您尝试过的内容。同时尝试添加您的数据库结构