title: Laravel 5.4: how to iterate through request array?
body: <p>My request data represents an array of new and existing items. I'm trying to through this array to update and create items. </p>
  
  <p>This is how I retrieve the array:</p>
  
  <pre><code>$userInput = $request-&gt;all();
  foreach( $userInput['items'] as $key=&gt;&amp;$item){
  </code></pre>
  
  <p>Later in the code I update an existing item:</p>
  
  <pre><code>$updateItem = Item::find($item['id']);
  $updateItem-&gt;number = $item['number'];
  $updateItem-&gt;save();
  </code></pre>
  
  <p>But <code>$item['number']</code> seems to contain old input from previous updates and not the value I entered last time.</p>
  
  <p>How can I loop through request data in Laravel ?</p>
  
  <p>This is the whole code as I run it (want to get rid of confusion):</p>
  
  <pre><code>$userInput = $request-&gt;all();
  // checking $userInput here
  // I can see the new value in the array
  
  foreach( $userInput['items'] as $key=&gt;$item){
    if($item['delete'] == 1) {
      Item::where('order_id',$order-&gt;id)
        -&gt;where('id',$item['id'])
        -&gt;delete();
    } else {
      if(empty($item['id'])) {
      } else {
        $updateItem = Item::find($item['id']);
        $updateItem-&gt;number = $item['id'];
        $updateItem-&gt;save();
      }
    }
  }
  </code></pre>
  
  <p>This is an input from html (just to show I checked the form also, the data comes just fine):</p>
  
  <pre><code>&lt;input id="basicItemNumber-31" class="form-control" name="items[31][number]" placeholder="Unique number" value="31" type="text"&gt;
  </code></pre>