@@ -149,6 +149,7 @@ public function first($columns = ['*']): mixed
149
149
$ result = $ this ->model ->first ($ columns );
150
150
151
151
$ this ->resetModel ();
152
+ $ this ->resetScope ();
152
153
153
154
return $ result ;
154
155
}
@@ -163,6 +164,7 @@ public function firstWhere(array $where, $columns = ['*']): mixed
163
164
$ result = $ this ->model ->first ($ columns );
164
165
165
166
$ this ->resetModel ();
167
+ $ this ->resetScope ();
166
168
167
169
return $ result ;
168
170
}
@@ -175,6 +177,7 @@ public function firstOrNew(array $attributes, array $values = []): mixed
175
177
$ model = $ this ->model ->firstOrNew ($ attributes , $ values );
176
178
177
179
$ this ->resetModel ();
180
+ $ this ->resetScope ();
178
181
179
182
return $ model ;
180
183
}
@@ -186,12 +189,15 @@ public function firstOrCreate(array $attributes, array $values = [], bool $witho
186
189
187
190
if (!is_null ($ model = $ this ->model ->where ($ attributes )->first ())) {
188
191
$ this ->resetModel ();
192
+ $ this ->resetScope ();
189
193
return $ model ;
190
194
}
191
195
192
196
$ method = $ withoutEvents ? 'saveQuietly ' : 'save ' ;
193
197
$ model = tap ($ this ->model ->newModelInstance ([...$ attributes , ...$ values ]), fn ($ instance ) => $ instance ->{$ method }());
198
+
194
199
$ this ->resetModel ();
200
+ $ this ->resetScope ();
195
201
196
202
event (new RepositoryEntityCreated ($ this , $ model ));
197
203
@@ -216,6 +222,7 @@ public function paginate($limit = null, $columns = ['*'], $method = "paginate"):
216
222
$ results ->appends (app ('request ' )->query ());
217
223
218
224
$ this ->resetModel ();
225
+ $ this ->resetScope ();
219
226
220
227
return $ results ;
221
228
}
@@ -229,8 +236,11 @@ public function find(mixed $id, $columns = ['*']): mixed
229
236
{
230
237
$ this ->applyCriteria ();
231
238
$ this ->applyScope ();
239
+
232
240
$ model = $ this ->model ->findOrFail ($ id , $ columns );
241
+
233
242
$ this ->resetModel ();
243
+ $ this ->resetScope ();
234
244
235
245
return $ model ;
236
246
}
@@ -239,8 +249,11 @@ public function findByField(string $field, $value = null, $columns = ['*']): mix
239
249
{
240
250
$ this ->applyCriteria ();
241
251
$ this ->applyScope ();
252
+
242
253
$ model = $ this ->model ->where ($ field , '= ' , $ value )->get ($ columns );
254
+
243
255
$ this ->resetModel ();
256
+ $ this ->resetScope ();
244
257
245
258
return $ model ;
246
259
}
@@ -253,7 +266,9 @@ public function findWhere(array $where, $columns = ['*']): mixed
253
266
$ this ->applyConditions ($ where );
254
267
255
268
$ model = $ this ->model ->get ($ columns );
269
+
256
270
$ this ->resetModel ();
271
+ $ this ->resetScope ();
257
272
258
273
return $ model ;
259
274
}
@@ -262,8 +277,11 @@ public function findWhereIn($field, array $values, $columns = ['*']): mixed
262
277
{
263
278
$ this ->applyCriteria ();
264
279
$ this ->applyScope ();
280
+
265
281
$ model = $ this ->model ->whereIn ($ field , $ values )->get ($ columns );
282
+
266
283
$ this ->resetModel ();
284
+ $ this ->resetScope ();
267
285
268
286
return $ model ;
269
287
}
@@ -272,8 +290,11 @@ public function findWhereNotIn($field, array $values, $columns = ['*']): mixed
272
290
{
273
291
$ this ->applyCriteria ();
274
292
$ this ->applyScope ();
293
+
275
294
$ model = $ this ->model ->whereNotIn ($ field , $ values )->get ($ columns );
295
+
276
296
$ this ->resetModel ();
297
+ $ this ->resetScope ();
277
298
278
299
return $ model ;
279
300
}
@@ -282,8 +303,11 @@ public function findWhereBetween($field, array $values, $columns = ['*']): mixed
282
303
{
283
304
$ this ->applyCriteria ();
284
305
$ this ->applyScope ();
306
+
285
307
$ model = $ this ->model ->whereBetween ($ field , $ values )->get ($ columns );
308
+
286
309
$ this ->resetModel ();
310
+ $ this ->resetScope ();
287
311
288
312
return $ model ;
289
313
}
@@ -325,6 +349,7 @@ public function update(array $attributes, int $id, bool $withoutEvents = false):
325
349
$ model ->{$ method }();
326
350
327
351
$ this ->resetModel ();
352
+ $ this ->resetScope ();
328
353
329
354
event (new RepositoryEntityUpdated ($ this , $ model ));
330
355
@@ -342,6 +367,7 @@ public function updateWhere(array $where, array $attributes, bool $withoutEvents
342
367
event (new RepositoryEntityUpdated ($ this , $ this ->model ->getModel ()));
343
368
344
369
$ this ->resetModel ();
370
+ $ this ->resetScope ();
345
371
346
372
return $ updated ;
347
373
}
@@ -352,7 +378,9 @@ public function updateOrCreate(array $attributes, array $values = [], bool $with
352
378
353
379
$ method = $ withoutEvents ? 'saveQuietly ' : 'save ' ;
354
380
$ model = tap ($ this ->model ->firstOrNew ($ attributes ), fn ($ instance ) => $ instance ->fill ($ values )->{$ method }());
381
+
355
382
$ this ->resetModel ();
383
+ $ this ->resetScope ();
356
384
357
385
event (new RepositoryEntityUpdated ($ this , $ model ));
358
386
@@ -366,6 +394,7 @@ public function upsert(array $values, array|string $uniqueBy, ?array $update = n
366
394
event (new RepositoryEntityCreated ($ this , $ this ->model ->getModel ()));
367
395
368
396
$ this ->resetModel ();
397
+ $ this ->resetScope ();
369
398
370
399
return $ upserted ;
371
400
}
@@ -386,6 +415,7 @@ public function deleteWhere(array $where, bool $forceDelete = false): ?bool
386
415
event (new RepositoryEntityDeleted ($ this , $ this ->model ->getModel ()));
387
416
388
417
$ this ->resetModel ();
418
+ $ this ->resetScope ();
389
419
390
420
return $ deleted ;
391
421
}
@@ -399,6 +429,7 @@ public function massDelete(): ?bool
399
429
event (new RepositoryEntityDeleted ($ this , $ this ->model ->getModel ()));
400
430
401
431
$ this ->resetModel ();
432
+ $ this ->resetScope ();
402
433
403
434
return $ deleted ;
404
435
}
@@ -556,6 +587,8 @@ public function getBaseQuery(): QueryBuilder
556
587
$ query = $ this ->model ->toBase ();
557
588
558
589
$ this ->resetModel ();
590
+ $ this ->resetScope ();
591
+
559
592
return $ query ;
560
593
}
561
594
@@ -591,6 +624,7 @@ protected function manageDeletes(int $id, string $method)
591
624
$ originalModel = clone $ model ;
592
625
593
626
$ this ->resetModel ();
627
+ $ this ->resetScope ();
594
628
595
629
$ model ->{$ method }();
596
630
0 commit comments