-
app/Rules/NoBlankCharacters.php
Open in GitHubuse Closure; use Illuminate\Contracts\Validation\ValidationRule; final readonly class NoBlankCharacters implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { $value = type($value)->asString(); if (preg_match("/\p{Cf}/u", $value)) { $fail('The :attribute field cannot contain blank characters.'); } } }
-
app/Http/Requests/UserUpdateRequest.php
Open in GitHubuse App\Rules\NoBlankCharacters; use Illuminate\Foundation\Http\FormRequest; final class UserUpdateRequest extends FormRequest { public function rules(): array { $user = type($this->user())->as(User::class); return [ 'name' => ['required', 'string', 'max:255', new NoBlankCharacters], // ... ]; } }