title: Laravel create or update many in a model linked relationship from form
body: <p>I want to create/update, all records from the form, I'm searching for a clean solution that doesn't use any loops, the following can be easily fixed with a loop. I'm using laravel 5.8</p>
  
  <p>Model <strong>Class:School</strong> -> HasMany (Model <strong>Class:Program</strong>)</p>
  
  <p><strong>This is the store method</strong> (this needs fixing)</p>
  
  <pre><code>public function store(Request $request, School $school)
  {
      $school-&gt;programs()-&gt;createMany(array($request-&gt;day, $request-&gt;schedule));
  }
  </code></pre>
  
  <p><strong>This is the update method</strong> (this needs fixing)</p>
  
  <pre><code>public function update(Request $request, School $school)
  {
      $school-&gt;programs()-&gt;update(array($request-&gt;day, $request-&gt;schedule));
  }
  </code></pre>
  
  <p>The form has a simple array input</p>
  
  <pre><code>&lt;td width&gt;&lt;input type="number" name="day[]" placeholder="Course Day (1-5)" class="form-control" /&gt;&lt;/td&gt;
  &lt;td width&gt;&lt;input type="text" name="schedule[]" placeholder="Actual schedule" class="form-control" /&gt;&lt;/td&gt;
  </code></pre>
  
  <p><a href="https://i.imgur.com/66egqVW.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/66egqVW.png" alt="enter image description here"></a>
  <a href="https://i.imgur.com/ZYYx6wt.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/ZYYx6wt.png" alt="enter image description here"></a></p>
  
  <ol>
  <li>How can I properly use createMany and pass an array of the
  arrays? </li>
  <li>How can I properly update the above arrays?</li>
  </ol>
  
  <p>Please try to provide a clean solution, I just created the example above to try and learn proper structuring and data management in laravel.</p>