From 186867c37fade890cab0b0a73502a56d55a5df5c Mon Sep 17 00:00:00 2001 From: marun Date: Wed, 4 Mar 2020 15:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CamelCase=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9Camel=E6=A0=BC=E5=BC=8F=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/src/Model/Concerns/CamelCase.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/database/src/Model/Concerns/CamelCase.php diff --git a/src/database/src/Model/Concerns/CamelCase.php b/src/database/src/Model/Concerns/CamelCase.php new file mode 100644 index 000000000..768a73c53 --- /dev/null +++ b/src/database/src/Model/Concerns/CamelCase.php @@ -0,0 +1,61 @@ +keyTransform($key), $attributes)) { + continue; + } + $attributes[$this->keyTransform($key)] = $this->mutateAttributeForArray( + $this->keyTransform($key), $attributes[$this->keyTransform($key)] + ); + } + return $attributes; + } + + public function jsonSerialize() + { + $array = []; + foreach ($this->toArray() as $key => $value) { + $array[$this->keyTransform($key)] = $value; + } + return $array; + } + + public function toArray(): array + { + $array = []; + foreach (parent::toArray() as $key => $value) { + $array[$this->keyTransform($key)] = $value; + } + return $array; + } + + public function toOriginalArray(): array + { + return parent::toArray(); + } +} \ No newline at end of file