title: UpdateOrCreate for multiplate tables, Laravel
body: <p>I have a function for create, but the code for update it's pretty similar so I want to modify the function to use <code>UpdateOrCreate</code> insted. </p>
  
  <pre><code>// Register table
  $register = new Register();
  $register-&gt;updateOrCreate(
      ['id' =&gt; $person],
      [
      'volume' =&gt; $request-&gt;volume,
          // more columns
  ]);
  
  // Person table
  $person = new Person();
  $person-&gt;updateOrCreate(
      ['id' =&gt; $request-&gt;register.id],
      [
      'name_as_written' =&gt; $request-&gt;name_as_written,
      //more columns
  ]);
  // $person-&gt;register()-&gt;associate($register)-&gt;save(); // right now, this is used for create
  
  
  // Relationship table
  foreach ($request-&gt;relationship_values as $item) {
      $relationship = new Relationship();
      $relationship-&gt;updateOrCreate(
          ['id' =&gt; $item.id],
          [
          'relative_surname' =&gt; $item['relative_surname'],
          //more columns
      ]);
  
    //  $relationship-&gt;person()-&gt;associate($person)-&gt;save(); // right now,this is used for create
  };
  </code></pre>