user() !== null; } /** * @return array> */ public function rules(): array { return [ 'first_name' => ['required', 'string', 'max:255'], 'last_name' => ['required', 'string', 'max:255'], 'username' => [ 'required', 'string', 'max:255', 'alpha_dash', function ($attribute, $value, $fail): void { if (User::whereKeyNot($this->user()->getKey()) ->whereRaw('LOWER(username) = ?', [strtolower($value)]) ->exists()) { $fail('The username has already been taken.'); } }, ], 'email' => [ 'required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->getKey()), ], ]; } }