|
1 | | -<?php declare(strict_types=1); |
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
2 | 4 |
|
3 | 5 | namespace Mavinoo\Batch\Traits; |
4 | 6 |
|
@@ -36,13 +38,56 @@ trait HasBatch |
36 | 38 | * @param array $values |
37 | 39 | * @param string|null $index |
38 | 40 | * @param bool $raw |
| 41 | + * |
39 | 42 | * @return bool|int |
40 | 43 | */ |
41 | 44 | public static function batchUpdate(array $values, string $index = null, bool $raw = false) |
42 | 45 | { |
43 | 46 | return app(Batch::class)->update(new static, $values, $index, $raw); |
44 | 47 | } |
45 | 48 |
|
| 49 | + /** |
| 50 | + * Update multiple condition rows |
| 51 | + * |
| 52 | + * @param array $arrays |
| 53 | + * @param string|null $keyName |
| 54 | + * @param bool $raw |
| 55 | + * |
| 56 | + * @return bool|int |
| 57 | + * @createdBy Mohammad Ghanbari <mavin.developer@gmail.com> |
| 58 | + * |
| 59 | + * @desc |
| 60 | + * Example |
| 61 | + * $table = new \App\Models\User; |
| 62 | + * $arrays = [ |
| 63 | + * [ |
| 64 | + * 'conditions' => ['id' => 1, 'status' => 'active'], |
| 65 | + * 'columns' => [ |
| 66 | + * 'status' => 'invalid' |
| 67 | + * 'nickname' => 'mohammad' |
| 68 | + * ], |
| 69 | + * ], |
| 70 | + * [ |
| 71 | + * 'conditions' => ['id' => 2], |
| 72 | + * 'columns' => [ |
| 73 | + * 'nickname' => 'mavinoo', |
| 74 | + * 'name' => 'mohammad', |
| 75 | + * ], |
| 76 | + * ], |
| 77 | + * [ |
| 78 | + * 'conditions' => ['id' => 3], |
| 79 | + * 'columns' => [ |
| 80 | + * 'nickname' => 'ali' |
| 81 | + * ], |
| 82 | + * ], |
| 83 | + * ]; |
| 84 | + * $keyName = 'id'; |
| 85 | + */ |
| 86 | + public function updateMultipleCondition(array $arrays, string $keyName = null, bool $raw = false) |
| 87 | + { |
| 88 | + return app(Batch::class)->updateMultipleCondition(new static, $arrays, $keyName, $raw); |
| 89 | + } |
| 90 | + |
46 | 91 | /** |
47 | 92 | * Insert multiple rows. |
48 | 93 | * |
@@ -89,6 +134,7 @@ public static function batchUpdate(array $values, string $index = null, bool $ra |
89 | 134 | * @param array $values |
90 | 135 | * @param int $batchSize |
91 | 136 | * @param bool $insertIgnore |
| 137 | + * |
92 | 138 | * @return bool|array |
93 | 139 | */ |
94 | 140 | public static function batchInsert(array $columns, array $values, int $batchSize = 500, bool $insertIgnore = false) |
|
0 commit comments