File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Askedio \SoftCascade \QueryBuilderSoftCascade ;
6
6
use Askedio \SoftCascade \Traits \ChecksCascading ;
7
+ use BadMethodCallException ;
7
8
use Illuminate \Database \Connection ;
8
9
use Illuminate \Database \Eloquent \SoftDeletingScope ;
9
10
use Illuminate \Database \Events \QueryExecuted ;
@@ -76,10 +77,11 @@ public function handle(): void
76
77
if (!is_null ($ event )) {
77
78
$ builder = $ event ['builder ' ];
78
79
79
- // add `withTrashed()`, if the model has SoftDeletes
80
- // otherwise, we can just skip it
81
- if (method_exists ($ builder , 'withTrashed ' )) {
80
+ try {
82
81
$ builder ->withTrashed ();
82
+ } catch (BadMethodCallException $ e ) {
83
+ // add `withTrashed()`, if the model has SoftDeletes
84
+ // otherwise, we can just skip it
83
85
}
84
86
85
87
$ keyName = $ builder ->getModel ()->getKeyName ();
Original file line number Diff line number Diff line change 7
7
use Askedio \SoftCascade \Exceptions \SoftCascadeNonExistentRelationActionException ;
8
8
use Askedio \SoftCascade \Exceptions \SoftCascadeRestrictedException ;
9
9
use Askedio \SoftCascade \Traits \ChecksCascading ;
10
+ use BadMethodCallException ;
10
11
use Illuminate \Database \Eloquent \Builder ;
11
12
use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
12
13
use Illuminate \Database \Eloquent \Relations \MorphOneOrMany ;
@@ -285,10 +286,10 @@ protected function withTrashed(Builder $builder): Builder
285
286
}
286
287
287
288
// if the Model does not use SoftDeletes, withTrashed() will be unavailable.
288
- if ( method_exists ( $ builder , ' withTrashed ' )) {
289
+ try {
289
290
return $ builder ->withTrashed ();
291
+ } catch (BadMethodCallException ) {
292
+ return $ builder ;
290
293
}
291
-
292
- return $ builder ;
293
294
}
294
295
}
You can’t perform that action at this time.
0 commit comments