How to handle null values when using Laravel's Eloquent with JSON columns in PHP?
I'm testing a new approach and I'm following best practices but I'm stuck on something that should probably be simple. I'm experiencing issues when trying to save data to a JSON column in my Laravel 9 application. I have a table with a JSON column named `settings`, and I'm attempting to store an array of settings. However, when some of the settings values are `null`, it seems to cause unexpected behavior. For example, if I run the following code: ```php $data = [ 'theme' => 'dark', 'notifications' => null, 'language' => 'en' ]; $user = User::find(1); $user->settings = $data; $user->save(); ``` I expect all settings to be saved, but when I retrieve the user model afterwards, the `notifications` key is missing entirely instead of being set to `null`. I’ve tried using `json_encode()` before assigning the data to the `settings` attribute, but that didn't resolve the scenario. I also checked that the `settings` column is indeed set to `json` type in my database migration: ```php $table->json('settings')->nullable(); ``` It seems like Laravel is omitting any keys with `null` values when saving to JSON columns. Is there a way to force Laravel to include keys with null values in the JSON column, or is there a best practice to handle this scenario? Any guidance would be greatly appreciated! For context: I'm using Php on macOS. Is there a better approach? Could this be a known issue?