user_id = $user->id; $secretCode->code = mt_rand(100000, 999999); $secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));; $secretCode->save(); } public static function updateSecretCode(User $user): void { $secretCode = SecretCode::where('user_id', $user->id)->first(); $secretCode->code = mt_rand(100000, 999999); $secretCode->save(); } public static function getCodeByUserId(int $user_id) { return SecretCode::where('user_id', $user_id)->one()->code; } public static function getByField(string $field, mixed $value) { return SecretCode::where($field, $value)->first(); } }