Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null timestamp in database - Carbon

I have a problem with the storage of zero date in the MySql database in the field of type timestamp. To read this field I use the Carbon library. When the value in database is equal 0000-00-00 00-00-00 Carbon converts it into a -0001-11-30 0:00:00. When saving to use a NULL value for the timestamp field. If I check if a date field is empty I must compare it to -0001-11-30 0:00:00. How can I solve this problem? Thank You!

like image 332
looozak Avatar asked Jul 13 '15 08:07

looozak


1 Answers

If you have created the tables using migration then for the date filed use nullable method to allow null value as default, for example:

$table->timestamp('dateFieldName')->nullable();

If you created the table using a differnt way then make sure that null value is allowed as default. Check this nice answer here for more information.

like image 85
The Alpha Avatar answered Sep 28 '22 07:09

The Alpha