mirror of
https://github.com/brian8544/turtle-wow.git
synced 2024-12-31 20:04:35 +00:00
30 lines
832 B
PHP
30 lines
832 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ReservedNames implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$caseInsensitiveValue = mb_strtolower($value);
|
|
$nameInLowerCase = DB::connection('mysql2')
|
|
->table('account_transfer_names')
|
|
->select(DB::raw('LOWER(name) as name'))
|
|
->whereRaw('LOWER(name) = ?', [$caseInsensitiveValue])
|
|
->first();
|
|
|
|
if ($nameInLowerCase) {
|
|
$fail(__('register_modal')['exception']['reserved_name']);
|
|
}
|
|
}
|
|
}
|