From 6d885ab894acecf6b6b7bca1e6493df383ff8b71 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 25 Aug 2022 17:36:06 +1200 Subject: [PATCH] FIX Normalise casing before casting fields --- src/View/ViewableData.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index 2755b1da4..204b05964 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -319,9 +319,12 @@ class ViewableData implements IteratorAggregate */ public function castingHelper($field) { - $specs = static::config()->get('casting'); - if (isset($specs[$field])) { - return $specs[$field]; + // Get casting if it has been configured. + // DB fields and PHP methods are all case insensitive so we normalise casing before checking. + $specs = array_change_key_case(static::config()->get('casting'), CASE_LOWER); + $fieldLower = strtolower($field); + if (isset($specs[$fieldLower])) { + return $specs[$fieldLower]; } // If no specific cast is declared, fall back to failover.