vendredi 14 décembre 2018

How do I sync an object with many items in Laravel

if I have this in laravel

form: { id: null, sale_number: 2, client: null, products: [ { product_id:"",description: "", quantity: null, price: null } ], }, how to sync many products if form{} is the request in model? :/ I have pivot table product_sale with extra fields quantity and price

I tried this...

$items =  $request->products;
$new= [];

    foreach( $items as $key => $item){

     $new[$item[$key]]= array('quantity' => 0,'price'=>0);

    }

$sale->products()->sync($new);

as example but can't get the product_id of every product to sync many thanks in advance :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire