title: How to Update data and Add new rows
body: <p>I have the <code>Invoice form</code> so sometime I want to update the data of the same Invoice number and add now rows.</p>
  
  <p>I want to update the data  and new rows on the same <code>Invoice No</code>, on my code below is update and add <code>one row</code> instead of add more than one rows which i have selected.</p>
  
  <p>supposed the invoice has one row and i want to update by add 10 rows on that Invoice number, so the code below is works but it update one row and add 1 new row instead of 10(news rows).</p>
  
  <p>My controller of update</p>
  
  <pre><code>public function update(Request $request, $inv_no)
  {
  
  $data = $request-&gt;all();
  
  $date = date ("Y-m-d",  strtotime($request-&gt;Indate));
  
  $stocks = Stock::where('inv_no', $inv_no)-&gt;get();
  $i = 0;
  
  foreach ($stocks as $stock) {  
      Stock::where('inv_no', $inv_no)
          -&gt;where('id', $stock-&gt;id)
          -&gt;update([
              'pid' =&gt; $request-&gt;pid[$i],
              'qty' =&gt; $request-&gt;qty[$i],
              'user_id' =&gt; Auth::user()-&gt;id,
              'Indate'=&gt;$date ,
              'supplierName' =&gt; $request-&gt;supplierName,
              'receiptNumber' =&gt; $request-&gt;receiptNumber,
              'truckNumber' =&gt; $request-&gt;truckNumber[$i],
              'driverName' =&gt; $request-&gt;driverName,
              'remark' =&gt; $request-&gt;remark,
          ]);
  
               $i++;
      }
  
  
      $totalPid = count($data['pid']);
      $totalQty = count($data['qty']);
      $totalTruckNumber = count($data['truckNumber']);
   // dd($stocks);
  
      if (count($stocks) &lt; $totalPid) {
          Stock::create([
              'pid' =&gt; $request-&gt;pid[$totalPid-1],
              'qty' =&gt; $request-&gt;qty[$totalQty-1],
              'inv_no' =&gt; $request-&gt;inv_no,
              'user_id' =&gt; Auth::user()-&gt;id,
              'Indate'=&gt;$date,
              'supplierName' =&gt; $request-&gt;supplierName,
              'receiptNumber' =&gt; $request-&gt;receiptNumber,
              'truckNumber' =&gt; $request-&gt;truckNumber[$totalTruckNumber-1],
              'driverName' =&gt; $request-&gt;driverName,
              'remark' =&gt; $request-&gt;remark,
          ]);
      }
  
  
  
  return  $this-&gt;show($inv_no)-&gt;with('success', 'GRN  Edited Successfully ');
  </code></pre>
  
  <p>}</p>
  
  <p>below is the Invoice form which i want to Update and Add new rows.
  <a href="https://i.stack.imgur.com/T74is.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T74is.png" alt="enter image description here"></a></p>
  
  <p>So I need the help what can i Add there to update and able to add more rows.</p>