vendredi 26 août 2016

Attach extra attributes to Laravel pivot table

I have 4 extra attributes ('product_id', 'quantity', 'discount_percent', 'discount_amount') in my pivot table, but my values for these are always 0 when I store, while the rest is populated properly. Any ideas?

Invoice model

public function productversion()
{
    return $this->belongsToMany('App\Productversion')->withPivot('product_id', 'quantity', 'discount_percent', 'discount_amount')->withTimestamps();
}

Productversion model

public function invoice()
{
    return $this->belongsToMany('App\Invoice')->withPivot('product_id', 'quantity', 'discount_percent', 'discount_amount')->withTimestamps();
}

Controller (store)

$invoice->productversion()->attach($productversionid, ['product_id' => $productid], ['quantity' => $qty], ['discount_percent' => $discountprc], ['discount_amount' => $discountamt]);



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

Aucun commentaire:

Enregistrer un commentaire