laravel - How can I set value for extra field on Eloquent pivot table -
$recourse->pivot->field = 'value';
gives error: indirect modification of overloaded property
pivot
available in context of relation:
// won't work $model = model::first(); $model->pivot; // null // work $anothermodel = anothermodel::first(); $relatedmodel = $anothermodel->relation()->first(); $relatedmodel->pivot; // pivot object
but trying use additional param in save
method:
$product = product::find($item->id); $order->product()->save($product, ['price' => 12.34]);
for existing relation:
$product = $order->product()->find($productid); $product->pivot->price = 12.34; $product->pivot->save(); // or $order->product()->updateexistingpivot($productid, ['price'=>12.34]);
and suggest use products
kind of relation in order make easier read.
Comments
Post a Comment