I want to know how can I make Laravel to get the current date and insert it into the database with the rest of the data from a form.
Thanks in advance.
I want to know how can I make Laravel to get the current date and insert it into the database with the rest of the data from a form.
Thanks in advance.
收起
Laravel comes with this functionality out of the box.
You can add this code to your migration:
$table->timestamps();
This will create a created_at
and updated_at
field in your database which are automatically filled.
Or if you want to don't want to do it within Laravel, you can do one of these:
TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
$model->created_at = date('Y-m-d');
and save it normally.报告相同问题?