Search code examples
phpmysqllaraveldatabase

How to set a default value of 1 year from now for expire_at in Laravel migrations?


I am creating fields for a table in Laravel. I want to create a expire_at column using $table->timestamps() but set a default date of 1 year from now.

Currently, I am trying the following:

$table->timestamps('expire_at')->default('1 year from now');

But this doesn't seem to work. How can I achieve this?

Any help would be appreciated.


Solution

  • You can use Carbon (Recommended)

    $table->timestamp('expire_at')->default(now()->addYear());