DEV Community

AquaCat
AquaCat

Posted on

3 1

【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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay