Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/VerificationCodeObserver.php
Show All 28 Lines | public function creating(VerificationCode $code): void | ||||
while (true) { | while (true) { | ||||
$code->code = Str::random($code_length); | $code->code = Str::random($code_length); | ||||
if (!VerificationCode::find($code->code)) { | if (!VerificationCode::find($code->code)) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (empty($code->expires_at)) { | |||||
$code->expires_at = Carbon::now()->addHours($exp_hours); | $code->expires_at = Carbon::now()->addHours($exp_hours); | ||||
} | } | ||||
// Verification codes are active by default | |||||
// Note: This is not required, but this way we make sure the property value | |||||
// is a boolean not null after create() call, if it wasn't specified there. | |||||
if (!isset($code->active)) { | |||||
vanmeeuwen: isn't that a database schema thing already? | |||||
$code->active = true; | |||||
} | |||||
} | |||||
} | } |
isn't that a database schema thing already?