Skip to content

Commit 60a198a

Browse files
authored
Added InvalidArgumentException (#692)
1 parent f714e49 commit 60a198a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Kris/LaravelFormBuilder/Fields/EntityType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ protected function pluck($value, $key, $data)
103103
//laravel 5.2.*
104104
return $data->lists($value, $key);
105105
}
106+
107+
throw new \InvalidArgumentException(sprintf(
108+
'Please provide valid "property" option for entity field [%s] in form class [%s]',
109+
$this->getRealName(),
110+
get_class($this->parent)
111+
));
106112
}
107113

108114
protected function get($data)
@@ -115,5 +121,11 @@ protected function get($data)
115121
//laravel 5.3.*
116122
return $data->get();
117123
}
124+
125+
throw new \InvalidArgumentException(sprintf(
126+
'Please provide valid "query_builder" option for entity field [%s] in form class [%s]',
127+
$this->getRealName(),
128+
get_class($this->parent)
129+
));
118130
}
119131
}

src/Kris/LaravelFormBuilder/Fields/FormField.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,24 @@ protected function getRenderData()
239239
protected function getModelValueAttribute($model, $name)
240240
{
241241
$transformedName = $this->transformKey($name);
242+
243+
if (is_null($model)) {
244+
return null;
245+
}
246+
242247
if (is_string($model)) {
243248
return $model;
244-
} elseif (is_object($model)) {
249+
}
250+
251+
if (is_object($model)) {
245252
return object_get($model, $transformedName);
246-
} elseif (is_array($model)) {
253+
}
254+
255+
if (is_array($model)) {
247256
return Arr::get($model, $transformedName);
248257
}
258+
259+
throw new \InvalidArgumentException('Invalid model given to field');
249260
}
250261

251262
/**

0 commit comments

Comments
 (0)