wip
This commit is contained in:
36
app/Rules/VerificationRule.php
Normal file
36
app/Rules/VerificationRule.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Auth\Verification;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class VerificationRule implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $phone
|
||||
*/
|
||||
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 (! $this->phone) {
|
||||
$fail(__('No phone provided'));
|
||||
}
|
||||
|
||||
Verification::where('username', $this->phone)
|
||||
->where('code', $value)
|
||||
->existsOr(fn () => $fail(__('Write a correct data please')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user