title: Undefined offset: 1 laravel
body: <p>i'm new to laravel
  I have a form with dynamic fields but when I create more than one dynamic field and click submit  this error appears: Undefined offset: 1
  but it's working with only one field.
  i saw who someone who used isset but i don't know how to use it in my case
  Can anyone tell me that why such error occurs in php</p>
  <p>Controller :</p>
  <pre><code>   public function store(Request $request)
  
  {   
      
      $data['invoice_no'] = $request-&gt;invoice_no;
          
      $data['last_invoice_no'] = $request-&gt;last_invoice_no;
      $data['devise'] = $request-&gt;devise;
      $data['customer_name'] = $request-&gt;customer_name;
      $data['customer_adress'] = $request-&gt;customer_adress;
      $data['invoice_no'] = $request-&gt;invoice_no;
      $data['invoice_date'] = $request-&gt;invoice_date;
    
      $data['company_adress'] = $request-&gt;company_adress;
      $data['company_name'] = $request-&gt;company_name;
      $data['company_phone'] = $request-&gt;company_phone;
      $data['poids_brut'] = $request-&gt;poids_brut;
      $data['poids_net'] = $request-&gt;poids_net;
      $data['livraison'] = $request-&gt;livraison;
      $data['incoterm'] = $request-&gt;incoterm;
      $data['payment_details'] = $request-&gt;payment_details;
      $data['sub_total'] = $request-&gt;sub_total;
      $data['shipping'] = $request-&gt;shipping;
      $data['total_due'] = $request-&gt;total_due;
      $data['created_by'] = (Auth::user()-&gt;name);
  
      $invoices = Invoices::create($data);
  
      $details_list = [];
      for ($i = 0; $i &lt; count($request-&gt;categorie_id); $i++) {
         
                                
          $details_list[$i]['categorie_id'] = $request-&gt;categorie_id[$i];
          $details_list[$i]['product_id'] = $request-&gt;product_id[$i];
          $details_list[$i]['size_id'] = $request-&gt;size_id[$i];
          $details_list[$i]['quantity'] = $request-&gt;quantity[$i];
          $details_list[$i]['unit_price'] = $request-&gt;unit_price[$i];
          $details_list[$i]['total_price'] = $request-&gt;total_price[$i];
          $details_list[$i]['created_by'] = (Auth::user()-&gt;name);
     
                 }
  
      $details = $invoices-&gt;details()-&gt;createMany($details_list);
  
      if ($details) {
          return redirect('/invoices')-&gt;with([
              'message' =&gt; __('la facture est créé avec succès'),
              'alert-type' =&gt; 'success'
          ]);
      } else {
          return redirect()-&gt;back()-&gt;with([
              'message' =&gt; __('la creation de facture a échoué'),
              'alert-type' =&gt; 'danger'
          ]);
      }
     
  
     }
  </code></pre>
  <p>Invoice Model :</p>
  <pre><code>class invoices extends Model
  {
       protected $guarded=[];
      public function details()
      {
          return $this-&gt;hasMany(invoice_products::class, 'invoice_id', 'id');
      }
  }
  </code></pre>
  <p>Invoice Products Model :</p>
  <pre><code>class invoice_products extends Model
  {
      protected $guarded=[];
  
      public function invoice()
      {
          return $this-&gt;belongsTo(Invoices::class, 'invoice_id', 'id');
      }
  }
  </code></pre>