Files
mtdb_movie/common/Auth/OtpCode.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

37 lines
834 B
PHP
Executable File

<?php
namespace Common\Auth;
use Illuminate\Database\Eloquent\Model;
class OtpCode extends Model
{
const TYPE_EMAIL_VERIFICATION = 'email_verification';
protected $guarded = ['id'];
protected $casts = [
'expires_at' => 'datetime',
];
public $timestamps = false;
public function isExpired(): bool
{
return now()->gte($this->expires_at);
}
public static function createForEmailVerification(int $userId)
{
self::where('user_id', $userId)
->where('type', static::TYPE_EMAIL_VERIFICATION)
->delete();
return static::create([
'user_id' => $userId,
'type' => static::TYPE_EMAIL_VERIFICATION,
'code' => random_int(100000, 999999),
'expires_at' => now()->addMinutes(30),
]);
}
}