samedi 29 septembre 2018

How to sync with pivot id in laravel

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);



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xZvTQg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire