diff --git a/src/Hydrator/EloquentHydrator.php b/src/Hydrator/EloquentHydrator.php index 82ae3ab9..e74f433e 100644 --- a/src/Hydrator/EloquentHydrator.php +++ b/src/Hydrator/EloquentHydrator.php @@ -77,7 +77,7 @@ class EloquentHydrator extends AbstractHydrator implements HydratesRelatedInterf * * @var string[] */ - protected $dates = []; + protected $dates = NULL; /** * Resource relationship keys that should be automatically hydrated. @@ -134,7 +134,7 @@ protected function hydrateAttributes(StandardObjectInterface $attributes, $recor } if ($attributes->has($resourceKey)) { - $data[$modelKey] = $this->deserializeAttribute($attributes->get($resourceKey), $resourceKey); + $data[$modelKey] = $this->deserializeAttribute($record, $attributes->get($resourceKey), $resourceKey); } } @@ -226,15 +226,16 @@ protected function keyForAttribute($resourceKey, Model $model) /** * Deserialize a value obtained from the resource's attributes. * + * @param $record * @param $value * the value that the client provided. * @param $resourceKey * the attribute key for the value * @return Carbon|null */ - protected function deserializeAttribute($value, $resourceKey) + protected function deserializeAttribute($record, $value, $resourceKey) { - if ($this->isDateAttribute($resourceKey)) { + if ($this->isDateAttribute($record, $resourceKey)) { return $this->deserializeDate($value); } @@ -253,11 +254,17 @@ protected function deserializeDate($value) /** * Is this resource key a date attribute? * + * @param $record * @param $resourceKey * @return bool */ - protected function isDateAttribute($resourceKey) + protected function isDateAttribute($record, $resourceKey) { + if(is_null($this->dates)) + { + return in_array(Str::snake($resourceKey), $record->getDates(), true); + } + return in_array($resourceKey, $this->dates, true); }