Skip to content

Commit

Permalink
feat: force casting
Browse files Browse the repository at this point in the history
  • Loading branch information
IsraelOrtuno committed Aug 1, 2023
1 parent 8a9cbae commit a39c37c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CastsModel.php
Expand Up @@ -82,4 +82,9 @@ public function newFromBuilder($attributes = [], $connection = null): static

return $instance->newFromBuilder($attributes, $connection);
}

public function forceCast(): static
{
return $this->newInstance($this->attributesToArray(), $this->exists);
}
}
7 changes: 7 additions & 0 deletions tests/CastsModelTest.php
Expand Up @@ -59,4 +59,11 @@
$model = new TabletDeviceModelTest();

expect($model->getMorphClass())->toBe('tablet');
});

it('forces model casting', function () {
$model = (new DeviceModelTest(['name' => 'phone']));
$model = $model->forceCast();

expect($model)->toBeInstanceOf(PhoneDeviceModelTest::class);
});

0 comments on commit a39c37c

Please sign in to comment.