Back

How to store empty DateTime input to Null value instead of 0000:00:00 00:00 value


Hi, i had two input Datetime field. User can choose to fill in either these two field. For the empty input Datetime field, i want it to store as Null value in Database. But currently the empty input Datetime field is store as 0000:00:00 00:00 value in Database. What code should i modified?

viiter replied 8 months ago

set the column default value to NULL in your database db structure

or in your migration script

$table->timestamp('start_date')->nullable();
saurabhd replied 8 months ago

Change you migration script according below given:

$table->timestamp('start_date')->nullable()->default(null);

Hope this work for you.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us