1. The parameter sent from the frontend is an empty string. See Figure 1.

{
"image": null,
"align": "center",
"title": "Image with text overlay",
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": {
"text": "Shop Now",
"url_object": {
"ID": 1,
"children": [],
"key": 3944,
"object": "home",
"object_id": 1,
"title": "Home",
"url": "/"
},
"url": "/"
},
"text_color": "#fff",
"button_text_color": "#000",
"button_background_color": "#fff",
"show_overlay": false,
"opacity": 0
}
2. After the backend saves it, the value of title is null.
{
"image": null,
"align": "center",
"title": null,
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": {
"text": "Shop Now",
"url_object": {
"ID": 1,
"children": [],
"key": 3944,
"object": "home",
"object_id": 1,
"title": "Home",
"url": "/"
},
"url": "/"
},
"text_color": "#fff",
"button_text_color": "#000",
"button_background_color": "#fff",
"show_overlay": false,
"opacity": 0
}
3. Print all request parameters on the backend using var_dump($request->all());. Confirm that the value of title has already been converted to null. See Figure 2.

4. Reference: https://learnku.com/docs/laravel/6.x/validation/5144#6633ca . By default, the global middleware stack in the Laravel application’s App\Http\Kernel class includes the ConvertEmptyStringsToNull middleware. This middleware converts empty strings to null.
5. However, hastily removing this middleware raises concerns that other features might be affected, and the scope of the impact would be difficult to assess. Review the implementation of ConvertEmptyStringsToNull.
/**
* Transform the given value.
*
* @param string $key
* @param mixed $value
* @return mixed
*/
protected function transform($key, $value)
{
return is_string($value) && $value === '' ? null : $value;
}
6. I decided to perform a reverse conversion: when returning the response to the frontend, check if the value is null, and if so, convert it back to an empty string. I ultimately chose to use the NULL coalescing operator.
// is_null($item['title']) ? '' : $item['title'];
$item['title'] ?? '';
