From d64c73453e23bbe5a097ac097e3d4a04a329de82 Mon Sep 17 00:00:00 2001 From: Attila Fulop Date: Sun, 3 Nov 2019 17:33:52 +0100 Subject: [PATCH] Minor polishes related to `toArray()` support --- Changelog.md | 6 +++--- src/CastsEnums.php | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4c2bd12..4e3a5fd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,10 +1,10 @@ # Changelog ### Konekt Enum Eloquent -## 1.3.2 -##### 2019-09-17 +## Unreleased +##### 2019-XX-XX -- Added support for Eloquent `toArray()` +- Added support for Eloquent `toArray()` (enums field values are properly included) ## 1.3.1 ##### 2019-09-08 diff --git a/src/CastsEnums.php b/src/CastsEnums.php index 9412636..afd6f8c 100644 --- a/src/CastsEnums.php +++ b/src/CastsEnums.php @@ -4,6 +4,7 @@ * * @copyright Copyright (c) 2017 Attila Fulop * @author Attila Fulop + * @author Nick Rupert * @license MIT * @since 2017-10-05 * @@ -90,19 +91,13 @@ protected function isEnumAttribute($key) return isset($this->enums[$key]); } - /** - * Add enum values to the attributes array - * - * @param $array - * @return array - */ - protected function addEnumAttributesToArray($array) + protected function addEnumAttributesToArray(array $attributes): array { foreach ($this->enums as $key => $value) { - $array[$key] = $this->getAttributeValue($key)->value(); + $attributes[$key] = $this->getAttributeValue($key)->value(); } - return $array; + return $attributes; } /**