diff --git a/app/Controllers/AreaGeoController.php b/app/Controllers/AreaGeoController.php index 009311c..b316c9f 100644 --- a/app/Controllers/AreaGeoController.php +++ b/app/Controllers/AreaGeoController.php @@ -1,7 +1,7 @@ */ - protected $helpers = []; + protected $helpers = ['json']; /** * Be sure to declare properties for any property fetch you initialized. diff --git a/app/Controllers/Contact/ContactController.php b/app/Controllers/Contact/ContactController.php index 22bcfcf..f3286c6 100644 --- a/app/Controllers/Contact/ContactController.php +++ b/app/Controllers/Contact/ContactController.php @@ -1,7 +1,7 @@ $value) { + if (is_array($value)) { + $data[$key] = convert_empty_strings_to_null($value); + } elseif (is_object($value)) { + $data[$key] = convert_empty_strings_to_null($value); + } elseif ($value === '') { + $data[$key] = null; + } + } + } elseif (is_object($data)) { + foreach ($data as $key => $value) { + if (is_array($value)) { + $data->$key = convert_empty_strings_to_null($value); + } elseif (is_object($value)) { + $data->$key = convert_empty_strings_to_null($value); + } elseif ($value === '') { + $data->$key = null; + } + } + } + return $data; + } +} + +if (!function_exists('prepare_json_response')) { + /** + * Prepare data for JSON response by converting empty strings to null + * This is a convenience wrapper around convert_empty_strings_to_null + * + * @param mixed $data The data to prepare for JSON response + * @return mixed The processed data ready for JSON encoding + */ + function prepare_json_response($data) { + return convert_empty_strings_to_null($data); + } +} diff --git a/app/Traits/ResponseTrait.php b/app/Traits/ResponseTrait.php new file mode 100644 index 0000000..ecfe63f --- /dev/null +++ b/app/Traits/ResponseTrait.php @@ -0,0 +1,31 @@ +baseRespond($data, $status, $message); + } +}