From 60a198a4c1b8669f81f033634c4320233b7a1e35 Mon Sep 17 00:00:00 2001 From: ukeloop <45733259+ukeloop@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:58:17 +0900 Subject: [PATCH] Added InvalidArgumentException (#692) --- src/Kris/LaravelFormBuilder/Fields/EntityType.php | 12 ++++++++++++ src/Kris/LaravelFormBuilder/Fields/FormField.php | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Kris/LaravelFormBuilder/Fields/EntityType.php b/src/Kris/LaravelFormBuilder/Fields/EntityType.php index 00db6c73..56d87baa 100644 --- a/src/Kris/LaravelFormBuilder/Fields/EntityType.php +++ b/src/Kris/LaravelFormBuilder/Fields/EntityType.php @@ -103,6 +103,12 @@ protected function pluck($value, $key, $data) //laravel 5.2.* return $data->lists($value, $key); } + + throw new \InvalidArgumentException(sprintf( + 'Please provide valid "property" option for entity field [%s] in form class [%s]', + $this->getRealName(), + get_class($this->parent) + )); } protected function get($data) @@ -115,5 +121,11 @@ protected function get($data) //laravel 5.3.* return $data->get(); } + + throw new \InvalidArgumentException(sprintf( + 'Please provide valid "query_builder" option for entity field [%s] in form class [%s]', + $this->getRealName(), + get_class($this->parent) + )); } } diff --git a/src/Kris/LaravelFormBuilder/Fields/FormField.php b/src/Kris/LaravelFormBuilder/Fields/FormField.php index be9b44f1..b5032140 100644 --- a/src/Kris/LaravelFormBuilder/Fields/FormField.php +++ b/src/Kris/LaravelFormBuilder/Fields/FormField.php @@ -239,13 +239,24 @@ protected function getRenderData() protected function getModelValueAttribute($model, $name) { $transformedName = $this->transformKey($name); + + if (is_null($model)) { + return null; + } + if (is_string($model)) { return $model; - } elseif (is_object($model)) { + } + + if (is_object($model)) { return object_get($model, $transformedName); - } elseif (is_array($model)) { + } + + if (is_array($model)) { return Arr::get($model, $transformedName); } + + throw new \InvalidArgumentException('Invalid model given to field'); } /**