Search
 
SCRIPT & CODE EXAMPLE
 

PHP

bulk update data in db query in 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));
Comment

PREVIOUS NEXT
Code Example
Php :: mysql between all months days even null 
Php :: get the matched value from 2 array in php 
Php :: 0 
Php :: mssql php 
Php :: pagination always show 5 pages 
Php :: bulk write mongodb php 
Php :: Laravel unique Validation with multiple column 
Php :: c# to php 
Php :: How to execute “php artisan migrate” and other Laravel commands in remote server? 
Php :: csv file import to mysqli using php 
Php :: how to enable auto refresh on save 
Php :: paginate array before more results php 
Php :: how to remove last element from php array 
Php :: PHP exif_read_data() 
Php :: true not true acf 
Php :: laravel search function 
Php :: laravel collection take 
Php :: doctrine orm refresh 
Php :: confirm popup laravel 
Php :: netchainmedia 
Php :: laravel validation messages 
Php :: laravel check if query builder is empty 
Php :: laravel make:action 
Php :: laravel get() 
Php :: The last ship -inurl:(htm/html/php/pls/txt) intitle:index.of "last modified" (mp4/wma/aac/avi) 
Php :: laravel blade @if 3 varabile 
Php :: spatie/laravel-activitylog display only changed data 
Php :: laravel, if -get() array is not emtpy 
Php :: laravel field types from database field type 
Php :: laravel 419 error 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =