create a rule to verify otp
This commit is contained in:
27
app/Rules/VerificationCode.php
Normal file
27
app/Rules/VerificationCode.php
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user