title: PHP How to save data from array to mysql using laravel 5
body: <p>Im getting an array within array of 'Cylinders' data from POST:</p>
  
  <pre><code>Array
    (
      [serie] =&gt; Array
          (
              [0] =&gt; 1234
              [1] =&gt; 3545
          )
  
      [seriesap] =&gt; Array
          (
              [0] =&gt; 1234234
              [1] =&gt; 345345
          )
  
      [type] =&gt; Array
          (
              [0] =&gt; 4546
              [1] =&gt; csdfwe
          )
  
      [admission] =&gt; Array
          (
              [0] =&gt; 04-05-2015
              [1] =&gt; 04-05-2015
          )
  
      [invoice] =&gt; Array
          (
              [0] =&gt; fei76867
              [1] =&gt; feiasodjf
          )
    )
  </code></pre>
  
  <p>Now, the fields inside the keys: serie, type, admission, etc dont change, but the info inside those key do change, i mean there could be even 15 items in there.</p>
  
  <p>At the end i need to save to the database:</p>
  
  <pre><code>$cylinder            = new Cylinder();
  $cylinder-&gt;serie     = ??;
  $cylinder-&gt;seriesap  = ??;
  $cylinder-&gt;type      = ??;
  $cylinder-&gt;admission = ??;
  $cylinder-&gt;invoice   = ??;
  $cylinder-&gt;save
  </code></pre>
  
  <p>How can i accomplish this task and save all the cylinders?</p>
  
  <p>I have tried all the foreach's that i could think of nothing seems to work.</p>
  
  <p>/<em>edit</em>/</p>
  
  <p>This is what Im doing so far:</p>
  
  <pre><code>$cyldata = $_POST['cylinder']; //this is the post from top.
  
  $num_elements = 0;
  
  while($num_elements &lt; count($cyldata['serie'])){
      $cylinder = new Cylinder();
      $cylinder-&gt;serie     = $cyldata['serie'][$num_elements];
      $cylinder-&gt;type      = $cyldata['type'][$num_elements];
      $cylinder-&gt;admission = $cyldata['admission'][$num_elements];
      $cylinder-&gt;seriesap  = $cyldata['seriesap'][$num_elements];         
      $cylinder-&gt;save
      $num_elements++;
  
  }
  </code></pre>
  
  <p>But it feels ugly, all those saves doesnt feel right. Dirty solution if you ask me.</p>