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.Laravel has the ability to save create and update timestamps in the database automatically.
All you need to do is add $table->timestamps()
to your migration. This will create two new fields: created_at
and updated_at
. Laravel will automatically populate those fields when creating/updating a model.
For automatically insertion you can use
$table->timestamps();
And for static entry you can use
$table->Date('Date_Of_Birth');