Skip to content

Commit

Permalink
Fix toArray & toJson
Browse files Browse the repository at this point in the history
  • Loading branch information
marcreichel committed Jan 16, 2019
1 parent df4063e commit 8d42f83
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,27 @@ protected function getEndpoint()
return $this->endpoint;
}

/**
* @return \Illuminate\Support\Collection
*/
private function getAttributes(): \Illuminate\Support\Collection
{
return collect($this->attributes)->merge($this->relations);
}

/**
* @return array
*/
public function toArray(): array
{
return $this->getAttributes()->toArray();
$attributes = $this->attributes;
$relations = collect($this->relations)->map(function($relation) {
return $relation->toArray();
});
return $attributes->merge($relations)->toArray();
}

/**
* @return string
*/
public function toJson(): string
{
return $this->getAttributes()->toJson();
$attributes = $this->attributes;
$relations = collect($this->relations)->map(function($relation) {
return $relation->toJson();
});
return $attributes->merge($relations)->toJson();
}
}

0 comments on commit 8d42f83

Please sign in to comment.