2
2
3
3
namespace Kirschbaum \PowerJoins \Mixins ;
4
4
5
+ use Illuminate \Database \Eloquent \Model ;
5
6
use Stringable ;
6
7
use Illuminate \Support \Str ;
7
8
use Kirschbaum \PowerJoins \StaticCache ;
16
17
use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
17
18
use Illuminate \Database \Eloquent \Relations \HasManyThrough ;
18
19
use Illuminate \Database \Eloquent \Relations \MorphOneOrMany ;
20
+ use Illuminate \Database \Eloquent \SoftDeletingScope ;
19
21
20
22
/**
21
23
* @method \Illuminate\Database\Eloquent\Model getModel()
@@ -86,7 +88,7 @@ protected function performJoinForEloquentPowerJoinsForBelongsTo()
86
88
"{$ joinedTable }. {$ this ->ownerKey }"
87
89
);
88
90
89
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getModel ())) {
91
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getScopes ())) {
90
92
$ join ->whereNull ("{$ joinedTable }. {$ this ->query ->getModel ()->getDeletedAtColumn ()}" );
91
93
}
92
94
@@ -139,7 +141,7 @@ protected function performJoinForEloquentPowerJoinsForBelongsToMany()
139
141
"{$ joinedTable }. {$ this ->getRelatedPivotKeyName ()}"
140
142
);
141
143
142
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getModel ())) {
144
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getScopes ())) {
143
145
$ join ->whereNull ($ this ->query ->getModel ()->getQualifiedDeletedAtColumn ());
144
146
}
145
147
@@ -200,7 +202,7 @@ protected function performJoinForEloquentPowerJoinsForMorphToMany()
200
202
"{$ joinedTable }. {$ this ->getRelatedPivotKeyName ()}"
201
203
);
202
204
203
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getModel ())) {
205
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getScopes ())) {
204
206
$ join ->whereNull ($ this ->query ->getModel ()->getQualifiedDeletedAtColumn ());
205
207
}
206
208
@@ -226,7 +228,7 @@ protected function performJoinForEloquentPowerJoinsForMorph()
226
228
"{$ this ->parent ->getTable ()}. {$ this ->localKey }"
227
229
)->where ("{$ this ->getModel ()->getTable ()}. {$ this ->getMorphType ()}" , '= ' , $ this ->getMorphClass ());
228
230
229
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getModel ())) {
231
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getScopes ())) {
230
232
$ join ->whereNull ($ this ->query ->getModel ()->getQualifiedDeletedAtColumn ());
231
233
}
232
234
@@ -249,6 +251,7 @@ protected function performJoinForEloquentPowerJoinsForMorph()
249
251
protected function performJoinForEloquentPowerJoinsForMorphTo ()
250
252
{
251
253
return function ($ builder , $ joinType , $ callback = null , $ alias = null , bool $ disableExtraConditions = false , string $ morphable = null ) {
254
+ /** @var Model */
252
255
$ modelInstance = new $ morphable ;
253
256
254
257
$ builder ->{$ joinType }($ modelInstance ->getTable (), function ($ join ) use ($ modelInstance , $ callback , $ disableExtraConditions ) {
@@ -258,7 +261,7 @@ protected function performJoinForEloquentPowerJoinsForMorphTo()
258
261
"{$ modelInstance ->getTable ()}. {$ modelInstance ->getKeyName ()}"
259
262
)->where ("{$ this ->getModel ()->getTable ()}. {$ this ->getMorphType ()}" , '= ' , $ modelInstance ->getMorphClass ());
260
263
261
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ modelInstance )) {
264
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ modelInstance-> getScopes () )) {
262
265
$ join ->whereNull ($ modelInstance ->getQualifiedDeletedAtColumn ());
263
266
}
264
267
@@ -304,7 +307,7 @@ protected function performJoinForEloquentPowerJoinsForHasMany()
304
307
"{$ parentTable }. {$ this ->localKey }"
305
308
);
306
309
307
- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getModel ())) {
310
+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this ->query ->getScopes ())) {
308
311
$ join ->whereNull (
309
312
"{$ joinedTable }. {$ this ->query ->getModel ()->getDeletedAtColumn ()}"
310
313
);
@@ -370,7 +373,7 @@ protected function performJoinForEloquentPowerJoinsForHasManyThrough()
370
373
"{$ throughTable }. {$ this ->secondLocalKey }"
371
374
);
372
375
373
- if ($ this ->usesSoftDeletes ($ this ->getModel ())) {
376
+ if ($ this ->usesSoftDeletes ($ this ->getScopes ())) {
374
377
$ join ->whereNull ("{$ farTable }. {$ this ->getModel ()->getDeletedAtColumn ()}" );
375
378
}
376
379
@@ -408,8 +411,15 @@ public function performHavingForEloquentPowerJoins()
408
411
*/
409
412
public function usesSoftDeletes ()
410
413
{
414
+ /**
415
+ * @param \Illuminate\Database\Eloquent\Model|array $model
416
+ */
411
417
return function ($ model ) {
412
- return in_array (SoftDeletes::class, class_uses_recursive ($ model ));
418
+ if ($ model instanceof Model) {
419
+ return in_array (SoftDeletes::class, class_uses_recursive ($ model ));
420
+ }
421
+
422
+ return array_key_exists (SoftDeletingScope::class, $ model );
413
423
};
414
424
}
415
425
0 commit comments