Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Listeners/CascadeQueryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Askedio\SoftCascade\QueryBuilderSoftCascade;
use Askedio\SoftCascade\Traits\ChecksCascading;
use BadMethodCallException;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Events\QueryExecuted;
Expand Down Expand Up @@ -77,11 +76,10 @@ public function handle(): void
if (!is_null($event)) {
$builder = $event['builder'];

try {
// add `withTrashed()`, if the model has SoftDeletes
// otherwise, we can just skip it
if (method_exists($builder, 'withTrashed')) {
$builder->withTrashed();
} catch (BadMethodCallException $e) {
// add `withTrashed()`, if the model has SoftDeletes
// otherwise, we can just skip it
}

$keyName = $builder->getModel()->getKeyName();
Expand Down
7 changes: 3 additions & 4 deletions src/SoftCascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Askedio\SoftCascade\Exceptions\SoftCascadeNonExistentRelationActionException;
use Askedio\SoftCascade\Exceptions\SoftCascadeRestrictedException;
use Askedio\SoftCascade\Traits\ChecksCascading;
use BadMethodCallException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany;
Expand Down Expand Up @@ -286,10 +285,10 @@ protected function withTrashed(Builder $builder): Builder
}

// if the Model does not use SoftDeletes, withTrashed() will be unavailable.
try {
if (method_exists($builder, 'withTrashed')) {
return $builder->withTrashed();
} catch (BadMethodCallException) {
return $builder;
}

return $builder;
}
}
Loading