Files
online.tbbank.gov.tm-larave…/app/Rules/PhoneCodeVerification.php

37 lines
865 B
PHP

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