title: Updating has many relationship in Laravel
body: <p>I'm building a small application in <code>Laravel 5.5</code> where I'm having two models: <code>Interaction</code> and <code>Interaction Summary</code> in my <code>Interaction</code> model I'm having following relationship:</p>
  
  <pre><code>public function meetingSummaries()
  {
      return $this-&gt;hasMany('App\InteractionSummary');
  }
  </code></pre>
  
  <p>Now to create the interaction I'm using following in my controller:</p>
  
  <pre><code>$data = $request-&gt;only('user_id', 'event_type', 'schedule', 'summaries', 'type', 'venue', 'with_client');
  $data['schedule'] = Carbon::parse($request-&gt;schedule)-&gt;addHours(5)-&gt;addMinutes(30)-&gt;toDateTimeString();
  $meeting = [];
  $meeting['user_id']= $data['user_id'];
  $meeting['schedule'] = $data['schedule'];
  $meeting['type'] = $data['type'];
  $meeting['with_client'] = $data['with_client'];
  $meeting['venue'] = $data['venue'];
  $meeting['event_type'] = $data['event_type'];
  $interaction = Interaction::create($meeting);
  if($data['summaries'])
  {
      $container = [];
      foreach($data['summaries'] as $summary)
      {
          $summary = (Object)$summary;
          if($summary-&gt;client['label'])
          {
              $container[] = new InteractionSummary([
                  'company_id' =&gt; $summary-&gt;client['label'],
                  'nature' =&gt; $summary-&gt;type,
                  'user_id' =&gt; $summary-&gt;mention['label'],
                  'action' =&gt; $summary-&gt;action,
                  'feedback' =&gt; $summary-&gt;comment
              ]);
              }
          }
      }
      $interaction-&gt;meetingSummaries()-&gt;saveMany($container);
  }
  </code></pre>
  
  <p>But while updating I don't know to overcome this, as in my fields there might be new or old relational data. I'm trying something like this:</p>
  
  <pre><code>if($data['summaries'])
  {
      $container = [];
      foreach($data['summaries'] as $summary)
      {
          $summary = (Object)$summary;
          if($summary-&gt;id)
          {
              $container[] = new InteractionSummary([
                  'id' =&gt; $summary-&gt;id,
                  'company_id' =&gt; $summary-&gt;client['value'],
                  'nature' =&gt; $summary-&gt;type,
                  'user_id' =&gt; $summary-&gt;mention['value'],
                  'action' =&gt; $summary-&gt;action,
                  'feedback' =&gt; $summary-&gt;comment
              ]);
          }
          else {
              $container[] = new InteractionSummary([
                  'company_id' =&gt; $summary-&gt;client['value'],
                  'nature' =&gt; $summary-&gt;type,
                  'user_id' =&gt; $summary-&gt;mention['value'],
                  'action' =&gt; $summary-&gt;action,
                  'feedback' =&gt; $summary-&gt;comment
              ]);
          }
      }
      $interaction-&gt;meetingSummaries()-&gt;save($container);
  }
  </code></pre>
  
  <p>Which is sending me error:</p>
  
  <blockquote>
    <p>Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, array given, called in ~\app\Http\Controllers\InteractionsController.php on line 449</p>
  </blockquote>
  
  <p>If I do:</p>
  
  <pre><code>$interaction-&gt;meetingSummaries()-&gt;saveMany($container);
  </code></pre>
  
  <p>I get repeated new fields.</p>
  
  <p>Guide me how to overcome this. Thanks.</p>