Skip to content

Commit

Permalink
Add alias for properties closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcidesrh committed Apr 5, 2021
1 parent ba341e8 commit a0bb0ee
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/GenericResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public function toArray($request)

foreach ($value as $key2 => $value2) {
try {
if ($this->{$key2} instanceof Collection) {
$data[$key2] = new GenericResourceCollection($this->{$key2}, $value2);
} else if (\gettype($this->{$key2}) === 'object') {
$data[$key2] = new GenericResource($this->{$key2}, $value2);
if ($this->$key2 instanceof Collection) {
$data[$key2] = new GenericResourceCollection($this->$key2, $value2);
} else if (\gettype($this->$key2) === 'object') {
$data[$key2] = new GenericResource($this->$key2, $value2);
}
//Property name change
else if(\gettype($this->{$value2}) === 'string' && ($this->$value2 || method_exists($this->resource, $value2) || property_exists($this->resource, $value2)))
else if((\gettype($value2) === 'string' && \gettype($this->$value2) === 'string') && ($this->$value2 || method_exists($this->resource, $value2) || property_exists($this->resource, $value2)))
$data[$key2] = $this->$value2;
else if (method_exists($this->resource, $key2) || property_exists($this->resource, $key2)) {
$data[$key2] = $this->$key2;
Expand All @@ -72,12 +72,12 @@ public function toArray($request)

$newKey = !\is_numeric($key) ? $key : $value;

if ($this->{$value} instanceof Collection) {
$data[$newKey] = new GenericResourceCollection($this->{$value});
} else if (\gettype($this->{$value}) === 'object') {
$data[$newKey] = new GenericResource($this->{$value});
} else if ($this->{$value} || method_exists($this->resource, $value) || property_exists($this->resource, $value)) {
$data[$newKey] = $this->{$value};
if ($this->$value instanceof Collection) {
$data[$newKey] = new GenericResourceCollection($this->$value);
} else if (\gettype($this->$value) === 'object') {
$data[$newKey] = new GenericResource($this->$value);
} else if ($this->$value || method_exists($this->resource, $value) || property_exists($this->resource, $value)) {
$data[$newKey] = $this->$value;
}

} catch (\Throwable $th) {
Expand Down

0 comments on commit a0bb0ee

Please sign in to comment.