attributes table: id, name attribute_values: id, attribute_id, value products: id, name
How can save pivot attribute_id along with attribute_value_id and product_id using sync in attribute_value_product table.
attribute model
public function attributevalues(){
return $this->hasMany('App\Model\AttributeValue');
}
attribute value model
public function attributes(){
return $this->belongsTo('App\Model\Attribute', 'attribute_id');
}
product model
public function attributes(){
return $this->belongsToMany('App\Model\Attribute', 'attribute_products');
}
public function attributeValues(){
return $this->belongsToMany('App\Model\AttributeValue', 'attribute_value_products');
}
product controller
$product->save();
$product->attributes()->sync($request->attribute);
$product->attributeValues()->sync($request->attribute_value);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire