Skip to content

Commit

Permalink
Add support for models without all columns
Browse files Browse the repository at this point in the history
  • Loading branch information
martio committed Mar 21, 2023
1 parent 335d16a commit 5d34412
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Normalizers/ModelNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ public function normalize(mixed $value): ?array
$properties = $value->toArray();

foreach ($value->getDates() as $key) {
$properties[$key] = $value->getAttribute($key);
if (isset($properties[$key])) {
$properties[$key] = $value->getAttribute($key);
}
}

foreach ($value->getCasts() as $key => $cast) {
if ($this->isDateCast($cast)) {
$properties[$key] = $value->getAttribute($key);
if (isset($properties[$key])) {
$properties[$key] = $value->getAttribute($key);
}
}
}

foreach ($value->getRelations() as $key => $relation) {
$key = $value::$snakeAttributes ? Str::snake($key) : $key;

$properties[$key] = $relation;
if (isset($properties[$key])) {
$properties[$key] = $relation;
}
}

return $properties;
Expand Down

0 comments on commit 5d34412

Please sign in to comment.