-
app/Rules/AlphaName.php
Open in GitHubuse Illuminate\Contracts\Validation\Rule; class AlphaName implements Rule { public function passes($attribute, $value) { if (! is_string($value) && ! is_numeric($value)) { return false; } return preg_match('/^(?:[\pL\pN\pM]+[\pZ\'_-])*[\pL\pN\pM]+$/u', $value) > 0; } public function message(): string { return trans('validation.alpha_name'); } }
-
app/Http/Requests/UsersRequest.php
Open in GitHubuse App\Rules\AlphaName; use Illuminate\Foundation\Http\FormRequest; class UsersRequest extends FormRequest { public function rules(): array { return [ 'name' => ['required', 'string', 'max:255', new AlphaName], 'email' => 'required|email|unique:users,email,' . auth()->user()->id, ]; } }