Skip to content

Commit

Permalink
Merge pull request #39 from cjmellor/38-approval-fails-for-models-wit…
Browse files Browse the repository at this point in the history
…h-a-morphmap

fix: Use with morphMaps
  • Loading branch information
cjmellor authored Oct 2, 2023
2 parents 9ba8674 + 820e1be commit 0994661
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Scopes/ApprovalStateScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0994661

Please sign in to comment.