title: Laravel update/edit using foreach loop
body: <p>I was trying to update my table but I couldn't make it work.. I always end up with the error:</p>
  
  <blockquote>
    <p>Invalid argument supplied for foreach()</p>
  </blockquote>
  
  <p><strong>Here is my Controller:</strong></p>
  
  <pre><code> public function show_score($id)
      {
  
          $scores = Score::with(['lead','subject'])-&gt;where(['subject_id'=&gt;$id])-&gt;get();
  
          return view('markbook.show_score',compact('scores'));
      }
  
      public function update_score(Request $request)
      {
          $id = $request-&gt;input('id');
  
           $scores = Score::find($id);
           foreach ($scores as $datas) {
           $datas-&gt;jan_ap=$request-&gt;input('jan_ap');
           $datas-&gt;jan_hm=$request-&gt;input('jan_hm');
           $datas-&gt;save();  
  
          }
  
  
      }
  
  route:
  Route::get('markbook/scores/{id}', 'MarkbookController@show_score' );
  Route::post('markbook/scores', 'MarkbookController@update_score'); 
  </code></pre>
  
  <p>Here is my table I'm trying to loop the updated score:</p>
  
  <p><a href="https://i.stack.imgur.com/kK7c2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kK7c2.jpg" alt="enter image description here"></a></p>