Skip to content
Merged
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
7 changes: 5 additions & 2 deletions src/PostData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yard\Data;

use BackedEnum;
use Carbon\CarbonImmutable;
use Corcel\Model\Post;
use ReflectionClass;
Expand Down Expand Up @@ -102,7 +103,7 @@ private static function dataClass(string $postType): string
if (null === $classFQN) {
return static::class;
}

if (! class_exists($classFQN)) {
throw new RuntimeException(sprintf('The class "%s" does not exist or is not autoloaded.', $classFQN));
}
Expand Down Expand Up @@ -137,7 +138,9 @@ private function loadMeta(int $id): void
$meta = $metaAttribute->newInstance();
$metaValue = $meta->getValue($id, $property->name, $this->metaPrefix());
if (null !== $metaValue && null !== $propertyTypeName) {
if ('Spatie\LaravelData\Data' === $propertyTypeName || is_subclass_of($propertyTypeName, 'Spatie\LaravelData\Data')) {
if (is_a($propertyTypeName, Data::class, true)) {
$metaValue = $propertyTypeName::from($metaValue);
} elseif (is_a($propertyTypeName, BackedEnum::class, true) && (is_int($metaValue) || is_string($metaValue))) {
$metaValue = $propertyTypeName::from($metaValue);
}
$property->setValue($this, $metaValue);
Expand Down