omrakhur
omrakhur

Reputation: 1402

MySQL - null values for datetime column returned as unix epoch in Laravel

There is a datetime column called paymentdatein my purchases table that I wish to keep as NULL until the user pays.

That way I can do an issetcheck to see if it has been made non null or not and then execute the rest of code accordingly.

However, even though a paymentdate value in MySQL for newly entered rows is clearly shown as NULL when seen in MySQL Workbench, whenever I dd the same row in my Laravel application, it shows the paymentdate value as the unix epoch. I want it to be shown as NULL or at least pass the checks for null.

Upvotes: 0

Views: 575

Answers (1)

upful
upful

Reputation: 960

To use Laravel's Eloquent with dates you must include the name of all date columns in the $dates property of the corresponding model class. This feature transform dates into Carbon objects which extends PHP's DateTime class. See Eloquent Date Mutators.

In your case you would have: protected $dates = ['paymentdate'];

Upvotes: 2

Related Questions