title: How can i get the last inserted id of a dynamic mutiple field and save to another database
body: <p>Hello i have a form that is dynamic.. meaning you can add multiple input fields in the form and under each form there is also a sub dynamic form .
  and in my db i have a invoice table and a section table, the invoice table serves as the main field while section is the sub field. now am trying to get the last inserted id of the data sent to the db. since its dynamic only one data is getting returned.</p>
  <p>i tried this code tho</p>
  <pre><code>foreach ($services as $key =&gt; $value) {
          $inv = new Invoice();
          $inv-&gt;receiver_email = $email;
          $inv-&gt;receiver_info = $info;
          $inv-&gt;render = $services[$key];
          $inv-&gt;total = $total;
          $inv-&gt;invoice = $invoice;
          $inv-&gt;tax = $tax;
  
          $inv-&gt;save();
          $invoice_id = array($inv-&gt;id);
          print_r($invoice_id);
  
  }
  foreach ($invoice_id as $idd =&gt; $va) {
  foreach($service as $key =&gt; $value){
      $dataforsec = [
          'service' =&gt; $service[$key],
          'rate' =&gt; $rate[$key],
          'invoice_id' =&gt; $va,
      ];
      // dd($dataforsec);
      DB::table('sections')-&gt;insert($dataforsec);
      }
  }
  </code></pre>
  <p>this saves only the last id. but its dynamic i can send in three data at a time i need to get the three data also.. Please help me. Thanks.</p>