在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mavinoo/laravelBatch开源软件地址(OpenSource Url):https://github.com/mavinoo/laravelBatch开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel BATCH (BULK)Insert and update batch (bulk) in laravel Install
Service Providerfile app.php in array providers :
Aliasesfile app.php in array aliases :
Example Update 1use App\Models\User;
$userInstance = new User;
$value = [
[
'id' => 1,
'status' => 'active',
'nickname' => 'Mohammad'
] ,
[
'id' => 5,
'status' => 'deactive',
'nickname' => 'Ghanbari'
] ,
];
$index = 'id';
Batch::update($userInstance, $value, $index); Example Update 2use App\Models\User;
$userInstance = new User;
$value = [
[
'id' => 1,
'status' => 'active'
],
[
'id' => 5,
'status' => 'deactive',
'nickname' => 'Ghanbari'
],
[
'id' => 10,
'status' => 'active',
'date' => Carbon::now()
],
[
'id' => 11,
'username' => 'mavinoo'
]
];
$index = 'id';
Batch::update($userInstance, $value, $index); Example Increment / Decrementuse App\Models\User;
$userInstance = new User;
$value = [
[
'id' => 1,
'balance' => ['+', 500] // Add
] ,
[
'id' => 2,
'balance' => ['-', 200] // Subtract
] ,
[
'id' => 3,
'balance' => ['*', 5] // Multiply
] ,
[
'id' => 4,
'balance' => ['/', 2] // Divide
] ,
[
'id' => 5,
'balance' => ['%', 2] // Modulo
] ,
];
$index = 'id';
Batch::update($userInstance, $value, $index); Example Insertuse App\Models\User;
$userInstance = new User;
$columns = [
'firstName',
'lastName',
'email',
'isActive',
'status',
];
$values = [
[
'Mohammad',
'Ghanbari',
'[email protected]',
'1',
'0',
] ,
[
'Saeed',
'Mohammadi',
'[email protected]',
'1',
'0',
] ,
[
'Avin',
'Ghanbari',
'[email protected]',
'1',
'0',
] ,
];
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
$result = Batch::insert($userInstance, $columns, $values, $batchSize); // result : false or array
sample array result:
Array
(
[totalRows] => 384
[totalBatch] => 500
[totalQuery] => 1
) Helper batch()// ex: update
$result = batch()->update($userInstance, $value, $index);
// ex: insert
$result = batch()->insert($userInstance, $columns, $values, $batchSize); TestsIf you don't have phpunit installed on your project, first run In the root of your laravel app, run DonateBTC Address: 16XDxkcqiEJ8DYf4xWxu7WK3Peo29TvXxD |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论