DEV Community

AquaCat
AquaCat

Posted on

【Laravel】timestamps() and timestamp()

*The version of Laravel ...5.8, PHP...7.1.3

When you create migrations in Laravel, you need to set columns that store timestamps ("created_at", "updated_at", "deleted_at").

$table->timestamps();
Enter fullscreen mode Exit fullscreen mode

It creates "created_at" and "updated_at" automatically and these columns can store NULL.

You also can set name for a single column for timestamp like as below.

$table->timestamp('<column name>');
Enter fullscreen mode Exit fullscreen mode

Make sure to use "timestamps()" (plural) to set "create_at" and "updated_at" at the same time, and for a single column, use "timestamp()" (not plural). Otherwise, you will waste hours and hours to fix the error like I did...

Top comments (0)