From 9bd0eb3c3cdccf5a39a2e2a5fe473adf4cad8a39 Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Fri, 2 Jun 2017 11:50:05 -0500 Subject: [PATCH 1/2] Allow direct arrays in fromJson I have a model that gets populated with a nested array. 'collection' attribute casts don't work when the $value isn't a json string, and throws an ErrorException: `json_decode() expects parameter 1 to be string, array given` --- src/Model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Model.php b/src/Model.php index a684e7d..177426b 100644 --- a/src/Model.php +++ b/src/Model.php @@ -763,6 +763,10 @@ protected function asJson($value) */ public function fromJson($value, $asObject = false) { + if(is_array($value)) { + return $value; + } + return json_decode($value, ! $asObject); } From 0b25fc55075417eaae1e0142706f27afddbc3286 Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Fri, 2 Jun 2017 11:50:58 -0500 Subject: [PATCH 2/2] Fixing style --- src/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model.php b/src/Model.php index 177426b..e7452dd 100644 --- a/src/Model.php +++ b/src/Model.php @@ -763,7 +763,7 @@ protected function asJson($value) */ public function fromJson($value, $asObject = false) { - if(is_array($value)) { + if (is_array($value)) { return $value; }