Improve support for BackedEnums

This commit is contained in:
Luke Towers 2023-09-02 19:47:53 -06:00 committed by GitHub
parent ca85e3c491
commit 32f25ef755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -700,18 +700,15 @@ class FormField
if ($result instanceof Model && $result->hasRelation($key)) {
if ($key == $lastField) {
$result = $result->getRelationValue($key) ?: $default;
}
else {
} else {
$result = $result->{$key};
}
}
elseif (is_array($result)) {
} elseif (is_array($result)) {
if (!array_key_exists($key, $result)) {
return $default;
}
$result = $result[$key];
}
else {
} else {
if (!isset($result->{$key})) {
return $default;
}
@ -719,6 +716,10 @@ class FormField
}
}
if ($result instanceof BackedEnum) {
$result = $result->value;
}
return $result;
}
}