Files
backend-mm/app/Rules/VerificationRule.php
2026-08-15 11:52:46 +05:00

42 lines
947 B
PHP

<?php
namespace App\Rules;
use App\Models\Auth\Verification;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Translation\PotentiallyTranslatedString;
class VerificationRule implements ValidationRule
{
/**
* Constructor
*
* @param string $phone
*/
public function __construct(protected null|int|string $phone)
{
//
}
/**
* Run the validation rule.
*
* @param Closure(string): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! $this->phone) {
$fail(__('No phone provided'));
}
if (isOtpBypass($this->phone, $value)) {
return;
}
Verification::where('username', $this->phone)
->where('code', $value)
->existsOr(fn () => $fail(__('Write a correct data please')));
}
}