@@ -13,13 +13,13 @@ Insert and update batch (bulk) in laravel
1313
1414# Service Provider
1515
16- file app.php in array providers :
16+ File ` app.php ` in array providers:
1717
1818` Mavinoo\Batch\BatchServiceProvider::class, `
1919
2020# Aliases
2121
22- file app.php in array aliases :
22+ File ` app.php ` in array aliases:
2323
2424` 'Batch' => Mavinoo\Batch\BatchFacade::class, `
2525
@@ -30,31 +30,31 @@ use App\Models\User;
3030
3131$userInstance = new User;
3232$arrays = [
33- [
34- 'conditions' => ['id' => 1, 'status' => 'active'],
35- 'columns' => [
36- 'status' => 'invalid'
37- 'nickname' => 'mohammad'
38- ],
39- ],
40- [
41- 'conditions' => ['id' => 2],
42- 'columns' => [
43- 'nickname' => 'mavinoo',
44- 'name' => 'mohammad',
45- ],
46- ],
47- [
48- 'conditions' => ['id' => 3],
49- 'columns' => [
50- 'nickname' => 'ali'
51- ],
52- ],
33+ [
34+ 'conditions' => ['id' => 1, 'status' => 'active'],
35+ 'columns' => [
36+ 'status' => 'invalid',
37+ 'nickname' => 'mohammad',
38+ ],
39+ ],
40+ [
41+ 'conditions' => ['id' => 2],
42+ 'columns' => [
43+ 'nickname' => 'mavinoo',
44+ 'name' => 'mohammad',
45+ ],
46+ ],
47+ [
48+ 'conditions' => ['id' => 3],
49+ 'columns' => [
50+ 'nickname' => 'ali',
51+ ],
52+ ],
5353];
5454$keyName = 'id';
5555
5656Batch::updateMultipleCondition($userInstance, $arrays, $keyName);
57- or
57+ // or
5858batch()->updateMultipleCondition($userInstance, $arrays, $keyName);
5959```
6060
@@ -65,21 +65,21 @@ use App\Models\User;
6565
6666$userInstance = new User;
6767$value = [
68- [
69- 'id' => 1,
70- 'status' => 'active',
71- 'nickname' => 'Mohammad'
72- ] ,
73- [
74- 'id' => 5,
75- 'status' => 'deactive',
76- 'nickname' => 'Ghanbari'
77- ] ,
68+ [
69+ 'id' => 1,
70+ 'status' => 'active',
71+ 'nickname' => 'Mohammad',
72+ ] ,
73+ [
74+ 'id' => 5,
75+ 'status' => 'deactive',
76+ 'nickname' => 'Ghanbari',
77+ ] ,
7878];
7979$index = 'id';
8080
8181Batch::update($userInstance, $value, $index);
82- or
82+ // or
8383batch()->update($userInstance, $values, $index);
8484```
8585
@@ -90,29 +90,29 @@ use App\Models\User;
9090
9191$userInstance = new User;
9292$value = [
93- [
94- 'id' => 1,
95- 'status' => 'active'
96- ],
97- [
98- 'id' => 5,
99- 'status' => 'deactive',
100- 'nickname' => 'Ghanbari'
101- ],
102- [
103- 'id' => 10,
104- 'status' => 'active',
105- 'date' => Carbon::now()
106- ],
107- [
108- 'id' => 11,
109- 'username' => 'mavinoo'
110- ]
93+ [
94+ 'id' => 1,
95+ 'status' => 'active',
96+ ],
97+ [
98+ 'id' => 5,
99+ 'status' => 'deactive',
100+ 'nickname' => 'Ghanbari',
101+ ],
102+ [
103+ 'id' => 10,
104+ 'status' => 'active',
105+ 'date' => Carbon::now(),
106+ ],
107+ [
108+ 'id' => 11,
109+ 'username' => 'mavinoo',
110+ ],
111111];
112112$index = 'id';
113113
114114Batch::update($userInstance, $value, $index);
115- or
115+ // or
116116batch()->update($userInstance, $values, $index);
117117```
118118
@@ -123,31 +123,31 @@ use App\Models\User;
123123
124124$userInstance = new User;
125125$value = [
126- [
127- 'id' => 1,
128- 'balance' => ['+', 500] // Add
129- ] ,
130- [
131- 'id' => 2,
132- 'balance' => ['-', 200] // Subtract
133- ] ,
134- [
135- 'id' => 3,
136- 'balance' => ['*', 5] // Multiply
137- ] ,
138- [
139- 'id' => 4,
140- 'balance' => ['/', 2] // Divide
141- ] ,
142- [
143- 'id' => 5,
144- 'balance' => ['%', 2] // Modulo
145- ] ,
126+ [
127+ 'id' => 1,
128+ 'balance' => ['+', 500], // Add
129+ ] ,
130+ [
131+ 'id' => 2,
132+ 'balance' => ['-', 200], // Subtract
133+ ] ,
134+ [
135+ 'id' => 3,
136+ 'balance' => ['*', 5], // Multiply
137+ ] ,
138+ [
139+ 'id' => 4,
140+ 'balance' => ['/', 2], // Divide
141+ ] ,
142+ [
143+ 'id' => 5,
144+ 'balance' => ['%', 2], // Modulo
145+ ] ,
146146];
147147$index = 'id';
148148
149149Batch::update($userInstance, $value, $index);
150- or
150+ // or
151151batch()->update($userInstance, $values, $index);
152152```
153153
@@ -158,44 +158,44 @@ use App\Models\User;
158158
159159$userInstance = new User;
160160$columns = [
161- 'firstName',
162- 'lastName',
163- 'email',
164- 'isActive',
165- 'status',
161+ 'firstName',
162+ 'lastName',
163+ 'email',
164+ 'isActive',
165+ 'status',
166166];
167167$values = [
168- [
169- 'Mohammad',
170- 'Ghanbari',
171- 'emailSample_1@gmail.com',
172- '1',
173- '0',
174- ] ,
175- [
176- 'Saeed',
177- 'Mohammadi',
178- 'emailSample_2@gmail.com',
179- '1',
180- '0',
181- ] ,
182- [
183- 'Avin',
184- 'Ghanbari',
185- 'emailSample_3@gmail.com',
186- '1',
187- '0',
188- ] ,
168+ [
169+ 'Mohammad',
170+ 'Ghanbari',
171+ 'emailSample_1@gmail.com',
172+ '1',
173+ '0',
174+ ] ,
175+ [
176+ 'Saeed',
177+ 'Mohammadi',
178+ 'emailSample_2@gmail.com',
179+ '1',
180+ '0',
181+ ] ,
182+ [
183+ 'Avin',
184+ 'Ghanbari',
185+ 'emailSample_3@gmail.com',
186+ '1',
187+ '0',
188+ ] ,
189189];
190190$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
191191
192192$result = Batch::insert($userInstance, $columns, $values, $batchSize);
193- or
193+ // or
194194$result = batch()->insert($userInstance, $values, $index);
195195```
196196
197197``` php
198- // result : false or array
198+ // result: false or array
199199
200200sample array result:
201201Array
@@ -237,12 +237,10 @@ User::batchInsert($columns, $values, $batchSize);
237237
238238``` php
239239// ex: update
240-
241240$result = batch()->update($userInstance, $value, $index);
242241
243242
244243// ex: insert
245-
246244$result = batch()->insert($userInstance, $columns, $values, $batchSize);
247245```
248246
0 commit comments