title: Laravel Update Related Model with push?
body: <p>I am stuck on updating a eagerloaded model that has a "hasMany" relation. </p>
  
  <p>I have one model like so:</p>
  
  <pre><code>class UserGroup extends Model
  {
  
    public function enhancements()
    {
      return $this-&gt;hasMany('App\UserGroupEnhancement');
    }
  
  }
  </code></pre>
  
  <p>My controller is passing $userGroup to the view like so:</p>
  
  <pre><code>$userGroup = $this-&gt;userGroup-&gt;with('enhancements')-&gt;whereId($id)-&gt;first();
  </code></pre>
  
  <p>and then in my view I have </p>
  
  <pre><code>  @foreach($userGroup-&gt;enhancements as $enhancement)
  
    &lt;label&gt;{{$enhancement-&gt;type}}&lt;/label&gt;
    &lt;input class="form-control" name="enhancements[{{$enhancement-&gt;id}}][price]" value="{{$enhancement-&gt;price}}"&gt;
  
    @endforeach
  </code></pre>
  
  <p>When updating, how do I update all of records in the enhancement relationship? It's passed back into multiple arrays. I am currently doing something like this. </p>
  
  <pre><code>public function update($id)
  {
      $userGroup = $this-&gt;userGroup-&gt;findOrFail($id);
      $enhancement = \Input::get('enhancements');
      if (is_array($enhancement)) {
          foreach ($enhancement as $enhancements_id =&gt; $enhancements_price) {
              $userGroup-&gt;enhancements()-&gt;whereId($enhancements_id)-&gt;update($enhancements_price);
          }
       }
   }
  </code></pre>
  
  <p>Is there a way I can do this without needing the foreach loop? I see the push() method, but seems to only work on a single array. </p>