create a rule to verify otp

This commit is contained in:
2025-01-04 13:14:14 +03:30
parent 7a761b4fb5
commit 294f89b4ad
5 changed files with 31 additions and 20 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Rules;
use App\Facades\Otp\Otp;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Translation\PotentiallyTranslatedString;
class VerificationCode implements ValidationRule
{
public function __construct(protected string $phone_number){}
/**
* Run the validation rule.
*
* @param \Closure(string): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$verified = Otp::verifyOtpToken($this->phone_number, $value);
if (!$verified) {
$fail('The :attribute is not valid.')->translate();
}
}
}