Mysql
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Mysql

Cập nhật / chỉnh sửa Laravel bằng vòng lặp foreach

Từ cuộc thảo luận trò chuyện, điều tìm thấy là bạn muốn cập nhật nhiều điểm số, được liệt kê trong tr, td. Bạn có thể thay đổi nó như thế này

Thay đổi chế độ xem

@foreach($scores as $score) 
    <tr> 
        <td>{{$score->lead->student_name}} <input type="hidden" name="scores[{{$loop->index}}][id]" value="{{$score->id}}"></td> 
        <td><input type="text" name="scores[{{$loop->index}}][jan_ap]" value="{{$score->jan_ap}}"></td> 
        <td><input type="text" name="scores[{{$loop->index}}][jan_hm]" value="{{$score->jan_hm}}"></td> 
    </tr> 
@endforeach 

Điểm cập nhật của bộ điều khiển

public function update_score(Request $request) 
{ 
    $scores = $request->input('scores');  //here scores is the input array param 

    foreach($scores as $row){
        $score = Score::find($row['id']); 
        $score->jan_ap = $row['jan_ap']; 
        $score->jan_hm = $row['jan_hm']; 
        $score->save(); 
    }
} 


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. SQL:Giới hạn về CASE (số lượng điều kiện WHEN, THEN)

  2. Khai báo biến trong Bash?

  3. Lệnh Alter trong Aurora DB (thêm một cột mới)

  4. PHP / PDO / MySQL:chèn vào MEDIUMBLOB lưu trữ dữ liệu xấu

  5. Tôi có thể lưu trữ giá dưới dạng số thập phân hoặc Số nguyên trong Mysql không?