Skip to content

Commit b000abd

Browse files
committed
Minor fix
1 parent bef7421 commit b000abd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Criteria/OnlyTrashedCriteria.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class OnlyTrashedCriteria implements CriteriaInterface
2121
*/
2222
public function apply(Model|Builder $model, RepositoryInterface $repository): mixed
2323
{
24-
if (!method_exists($model, 'onlyTrashed'))
24+
$model = $model instanceof Builder ? $model->getModel() : $model;
25+
26+
if (!in_array(SoftDeletes::class, class_uses($model)))
2527
throw new RepositoryException('Model must implement SoftDeletes Trait to use this criteria.');
2628

2729
return $model->onlyTrashed();

src/Criteria/WithTrashedCriteria.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class WithTrashedCriteria implements CriteriaInterface
2121
*/
2222
public function apply(Model|Builder $model, RepositoryInterface $repository): mixed
2323
{
24-
if (!method_exists($model, 'withTrashed'))
24+
$model = $model instanceof Builder ? $model->getModel() : $model;
25+
26+
if (!in_array(SoftDeletes::class, class_uses($model)))
2527
throw new RepositoryException('Model must implement SoftDeletes Trait to use this criteria.');
2628

2729
return $model->withTrashed();

0 commit comments

Comments
 (0)