/laravel-batch

Laravel Batch Update

Primary LanguagePHPMIT LicenseMIT

laravel-builder-batch

Laravel Model 批处理

/**
 * $option['other']
 * $option['type']
 * $option['key'] 默认主键
 **/
simpleBatch(string $column, array $values = [], array $option = []):int
  1. 无Other
User::query()->simpleBatch('password', [1 => '123', 2 => '321']);
//DB::table('users')->simpleBatch('password', [1 => '123', 2 => '321']);
update `users` set `users`.`password` = ( case `users`.`id` when 1 then '123' when 2 then '321' end ), `users`.`updated_at` = "2022-02-08 15:42:32" where `users`.`id` in (1, 2);
  1. 有Other
User::query()->simpleBatch('password', [1 => '123', 2 => '321'],['other'=>'8888']);
//DB::table('users')->simpleBatch('password', [1 => '123', 2 => '321'],['other'=>'8888']);
update `users` set `users`.`password` = ( case `users`.`id` when 1 then '123' when 2 then '321' else '8888' end ), `users`.`updated_at` = "2022-02-08 15:45:11";
  1. ['+', '-', '*', '/', '%']
User::query()->simpleBatch('password', [1 => '123', 2 => '321'], ['type' => '+']);
// DB::table('users')->simpleBatch('password', [1 => '123', 2 => '321'], ['type' => '+']);
update `users` set `users`.`password` = ( case `users`.`id` when 1 then `users`.`password` + 123 when 2 then `users`.`password` + 321 end ), `users`.`updated_at` = "2022-02-08 15:42:32" where `users`.`id` in (1, 2);