Data Pembaruan Massal dalam Kueri DB di Laravel 8
$sqlInsert = array(
array('id'=>1, 'temp'=>1),
array('id'=>2, 'temp'=>2),
array('id'=>3, 'temp'=>3),
);
// prepare one query
$q = "UPDATE table_name SET temp= CASE id ";
foreach($sqlInsert as $insert) {
$q .= "WHEN '".$insert['id']."' THEN ".$insert['temp']." ";
}
$q .= "END WHERE id IN (";
foreach($sqlInsert as $insert) {
$q .= "'".$insert['id']."', ";
}
$q = rtrim($q, ", ");
$q .= ")";
// Update
DB::update(DB::raw($q));
Tyagi420