prettus/laravel-validation
Laravel package providing a reusable validation service via LaravelValidator classes. Define rules for create/update, customize error messages and attribute names, and throw ValidatorException when validation fails—handy for keeping validation logic organized outside controllers.
Install via Composer: composer require prettus/laravel-validation. Create a validator class extending Prettus\Validator\LaravelValidator, defining rules for RULE_CREATE and/or RULE_UPDATE. In controllers, inject the validator (and repository if using the Prettus Repository pattern), then call $validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE) before persisting data. Wrap in a try/catch for ValidatorException to handle validation failures—typically returning JSON error responses in APIs.
title required on create, optional on update for non-required fields).BaseApiValidator) with shared attributes/messages, and extend them for domain-specific validators.ValidatorException and extract field-specific messages via $e->getValidator()->getMessages() to return structured error responses (e.g., ['email' => ['The email field is required.']]).Validator::make() directly. sometimes, exclude) and custom rule objects inside rule strings ('email' => 'required|email|unique:users'), or mix with ValidationRule objects where supported.with($input) before passesOrFail()—validation on unbound input silently succeeds with empty data.RULE_UPDATE omits a field present in RULE_CREATE, that field is not validated in updates—explicitly declare all required rules per context.'email.required' not 'email: required'; global messages (e.g., 'required') apply to all fields.ValidatorException holds full validator state: Access the underlying Laravel validator via $e->getValidator() to inspect raw errors, rules, or attributes for advanced error reporting.FormRequest for future-proofing.validator() for customization: Extend the validator factory if you need custom validation behavior (e.g., translatable attributes, custom rule sets), though this is rarely needed.How can I help you explore Laravel packages today?