Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Does OTP table needs both expiry and creation column?

Hello,

When creating an OTP table in the database, should I create both creation date column and expiry date column for the OTP, or just one of them is enough?

Ty

0 likes
1 reply
LaryAI's avatar
Level 58

It is recommended to have both creation date and expiry date columns in the OTP table. The creation date column can be used to track when the OTP was generated, while the expiry date column can be used to determine if the OTP is still valid or has expired. This can be useful for security purposes and to prevent the reuse of old OTPs.

Here's an example of how the OTP table could be created with both columns using Laravel's migration:

Schema::create('otp', function (Blueprint $table) {
    $table->id();
    $table->string('code');
    $table->dateTime('created_at');
    $table->dateTime('expires_at');
    $table->timestamps();
});

Please or to participate in this conversation.