From 820e1be3b04fbe9247b6bc275f957475acdd0364 Mon Sep 17 00:00:00 2001 From: Chris Mellor Date: Tue, 3 Oct 2023 00:31:37 +0100 Subject: [PATCH] fix: use with morphMaps --- src/Scopes/ApprovalStateScope.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Scopes/ApprovalStateScope.php b/src/Scopes/ApprovalStateScope.php index 6b99c90..52d61f1 100644 --- a/src/Scopes/ApprovalStateScope.php +++ b/src/Scopes/ApprovalStateScope.php @@ -8,6 +8,7 @@ use Cjmellor\Approval\Events\ModelSetPending; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Scope; use Illuminate\Support\Facades\Event; @@ -96,7 +97,8 @@ protected function addApprove(Builder $builder): void $modelId = $builder->getModel()->approvalable_id; - $model = new $modelClass(); + $morphedModel = Relation::getMorphedModel($modelClass) ?? $modelClass; + $model = new $morphedModel(); if ($modelId) { $model = $model->find($modelId);