v1.0
1.0.0.0Generates an update string based on the data you supply, and runs the query.
MIT
Wallogit.com
2017 © Pedro Peláez
Insert and update batch (bulk) in laravel
Insert and update batch (bulk) in laravel, (*1)
composer require goldenboy1991/laravel-batch:dev-master, (*2)
file app.php in array providers :, (*3)
Goldenboy\LaravelBatch\LaravelBatchServiceProvider::class,, (*4)
file app.php in array aliases :, (*5)
'Batch' => Goldenboy\LaravelBatch\LaravelBatchFacade::class,, (*6)
$table = 'users';
$value = [
[
'id' => 1,
'status' => 'active',
'nickname' => 'Mohammad'
] ,
[
'id' => 5,
'status' => 'deactive',
'nickname' => 'Ghanbari'
] ,
];
$index = 'id';
Batch::update($table, $value, $index);
$table = 'users';
$value = [
[
'id' => 1,
'status' => 'active'
],
[
'id' => 5,
'status' => 'deactive',
'nickname' => 'Ghanbari'
],
[
'id' => 10,
'status' => 'active',
'date' => Carbon::now()
],
[
'id' => 11,
'username' => 'goldenboy'
]
];
$index = 'id';
Batch::update($table, $value, $index);
$table = 'users';
$columns = [
'firstName',
'lastName',
'email',
'isActive',
'status',
];
$values = [
[
'Mohammad',
'Ghanbari',
'emailSample_1@gmail.com',
'1',
'0',
] ,
[
'Saeed',
'Mohammadi',
'emailSample_2@gmail.com',
'1',
'0',
] ,
[
'Avin',
'Ghanbari',
'emailSample_3@gmail.com',
'1',
'0',
] ,
];
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
$result = Batch::insert($table, $columns, $values, $batchSize);
// result : false or array
sample array result:
Array
(
[totalRows] => 384
[totalBatch] => 500
[totalQuery] => 1
)
Generates an update string based on the data you supply, and runs the query.
MIT