title: Save multiple rows to database from dynamic forms in Laravel 5
body: <p>I'm using jQuery to generate two dynamic fields. Each pair of fields is displayed on the page and can have multiple instances. On submit (not ajax), each pair of fields is saved into the their own table row along with <code>Auth::id()</code>.</p>
  
  <p>There are two forms in the HTML code, both values are entered, user clicks 'Add link' then jQuery creates two hidden fields (these are the ones that get submitted) and data entered appears (appended) visually to <code>#link-list</code>. The original fields become empty and the process can repeat...</p>
  
  <p>I'm struggling to create an array that is recognised by eloquent to save the data multiple times.</p>
  
  <p>I get the error 'Undefined index: link' or whichever the second input row is in jQuery.</p>
  
  <p>Blade/HTML:</p>
  
  <pre><code>{!! Form::open(['route' =&gt; ['multiple.store'], 'method' =&gt; 'post', 'role'=&gt; 'form', 'class' =&gt; 'form']) !!}
  
      &lt;ul id="link-list"&gt;
          &lt;!-- append new rows --&gt;
      &lt;/ul&gt;
  
      &lt;div id="newlink" class="form-inline"&gt;
          &lt;div class="form-group"&gt;
              {!! Form::text('prestore', null, ['placeholder' =&gt; 'Store name', 'class' =&gt; 'form-control']) !!}
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              {!! Form::text('prelink', null, ['placeholder' =&gt; 'Link / URL', 'class' =&gt; 'form-control']) !!}
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;button class="btn btn-primary submit new-row" type="button"&gt;Add store link&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;br/&gt;&lt;br/&gt;
  
      {!! Form::submit('Submit rows', ['class' =&gt; 'btn btn-success submit']) !!}
  
  {!! Form::close() !!}
  </code></pre>
  
  <p>jQuery/JavaScript</p>
  
  <pre><code>$(document).on('click', '.new-row', function() {
      var store = $('#newlink input[name=prestore]').val();
      var link = $('#newlink input[name=prelink]').val();
      console.log(store, link);
      $('&lt;li class="not-saved"&gt;' +
              '&lt;a href="'+link+'"&gt;'+store+'&lt;/a&gt;' +
              '&lt;input type="hidden" name="rows[][link]" value="' + link + '"&gt;' +
              '&lt;input type="hidden" name="rows[][store]" value="' + store + '"&gt;' +
          '&lt;/li&gt;').appendTo('#link-list').hide().fadeIn(280);
      $('input[name=prestore]').val('');
      $('input[name=prelink]').val('');
  });
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function store()
  {
      $input = Input::all();
  
      foreach ($input['rows'] as $row) {
          $items = new Multiple([
              'user_id' =&gt; Auth::id(),
              'store' =&gt; $row['store'],
              'link' =&gt; $row['link'],
          ]);
          $items-&gt;save();
      }
  }
  </code></pre>