PHP code example of quangpv / fast-bulk-update

1. Go to this page and download the library: Download quangpv/fast-bulk-update library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

quangpv / fast-bulk-update example snippets


use App\Models\User;

$model = App::make(User::class);

// If you wish to modify the database connection, you can set it on your model.
$model->setConnection('mariadb');
$model->setConnection('mysql');
$model->setConnection('pgsql');

$values = [
     [
         'id' => 1,
         'code' => 'UC01',
         'nickname' => 'quangpv'
     ] ,
     [
         'id' => 2,
         'code' => 'UC02',
         'nickname' => 'haiza'
     ] ,
];

// We will find the records by their IDs and update them.
$indexes = ['id']; // primary key
// $indexes = ['code', 'id']; // composite primary key

$updateFields = ['nickname']; // only update the field `nickname`
// $updateFields = []; // update all fields

$affectedRows = \BatchUpdate::execute($model, $values, $indexes, $updateFields);