I was wondering what would be the easiest way to change in laravel to save timestamps in database as unix valid timestamp?
Thanks in advance!
Please read about Laravel date mutators: https://laravel.com/docs/5.1/eloquent-mutators#date-mutators
By default, timestamps are formatted as 'Y-m-d H:i:s'. If you need to customize the timestamp format, set the $dateFormat property on your model. This property determines how date attributes are stored in the database, as well as their format when the model is serialized to an array or JSON
Also, you can override getDateFormat()
:
protected function getDateFormat()
{
return 'U';
}
And use this in your migration files:
$table->integer('updated_at');
$table->integer('created_at');
And, if you use soft deletes:
$table->integer('deleted_at');
https://laravel.com/docs/4.2/eloquent#timestamps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With