Level 75
Have a utility class and do something like:
public function fixInt($tonl) {
$this->tonl = (is_null($tonl) || empty($tonl) || strlen($tonl) < 1 ? NULL : $tonl);
return $this->tonl;
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What's the best practice when it comes to handling date/datetime columns that are optional (and set to nullable)?
I have several tables with a large number of optional date columns, but they are being saved as '2030-01-11' when creating or updating records if no value is specified.
I know I could use mutators, but that seems a bit laborious when there are many columns to handle.
Thanks
Please or to participate in this conversation.