lundi 25 septembre 2017

how to update array in laravel 5?

I am trying to update values from an array. i can create but if I try to update, it updates only last value. if I use save() i get an error. I tried everything i could researching. no success. here is my code.

$products = $request->all();

      $name = $products['name'];
      $price = $products['price'];
      $qty = $products['qty'];
      $total = $products['total'];

    foreach( $name as $key => $n) {

        $invoice->products()->update([ 

            'invoice_id' => $invoice->id,
            'name' => $name[$key],
            'price' => $price[$key],
            'qty' => $qty[$key],
            'total' => $total[$key]
        ]);



     }   

if I use save() i get this error

Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, array given,

thanks



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

Aucun commentaire:

Enregistrer un commentaire