Skip to content

Commit

Permalink
Fix Relation Array Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcreichel committed Jan 16, 2019
1 parent d0a2adb commit 1d3b8ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ public function toArray(): array
{
$attributes = collect($this->attributes);
$relations = collect($this->relations)->map(function($relation) {
if (is_array($relation)) {
return collect($relation)->map(function($single) {
return $single->toArray();
});
}
return $relation->toArray();
});
return $attributes->merge($relations)->sortKeys()->toArray();
Expand All @@ -284,6 +289,11 @@ public function toJson(): string
{
$attributes = collect($this->attributes);
$relations = collect($this->relations)->map(function($relation) {
if (is_array($relation)) {
return collect($relation)->map(function($single) {
return $single->toJson();
});
}
return $relation->toJson();
});
return $attributes->merge($relations)->sortKeys()->toJson();
Expand Down

0 comments on commit 1d3b8ba

Please sign in to comment.