31 lines
736 B
PHP
31 lines
736 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 int|string $phone,
|
|
) {}
|
|
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$verification = Verification::where('username', $this->phone)
|
|
->where('code', $value)
|
|
->first();
|
|
|
|
if (! $verification) {
|
|
$fail(__('Write a correct data please'));
|
|
}
|
|
}
|
|
}
|