mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-04 22:31:58 +01:00
25 lines
622 B
PHP
25 lines
622 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CaseInsensitiveEmailExists implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail) : void
|
|
{
|
|
$user = DB::table('users')
|
|
->whereRaw('email = ?' . (config('database.default') === 'sqlite' ? ' COLLATE NOCASE' : ''), [strtolower($value)])
|
|
->first();
|
|
|
|
if (! $user) {
|
|
$fail('validation.custom.email.exists')->translate();
|
|
}
|
|
}
|
|
}
|