diff --git a/src/Transformers/RestfulTransformer.php b/src/Transformers/RestfulTransformer.php index d60dd3f..3ccb7bb 100644 --- a/src/Transformers/RestfulTransformer.php +++ b/src/Transformers/RestfulTransformer.php @@ -123,7 +123,7 @@ protected function transformKeysCase(array $transformed) /* * However, if the level is 1, we also want to transform the first level of keys in a json field which has been cast to array */ - if ($levels == 1) { + if ($levels == 1 && ! is_null($this->model)) { foreach ($this->model->getCasts() as $fieldName => $castType) { if ($castType == 'array') { $fieldNameFormatted = $this->formatKeyCase($fieldName);