datalogix/laravel-validation
A Laravel package that extends the built-in validator with reusable custom validation rules and helpers, helping you organize validation logic and apply consistent rules across forms and requests.
This is a patch release (v4.0.1) on top of v4.0.0 — no API changes, so upgrading is a composer update datalogix/laravel-validation away. It fixes untranslated messages for several rules and documents placeholder usage.
First steps:
composer require datalogix/laravel-validation (Laravel package discovery registers the service provider; no manual wiring needed).Hetu, PortugueseNif, Mimetype, Uploaded, BetweenExclusive, ContainsCount, PublicDomainSuffix, …). The class constructor signature tells you what parameters it accepts.en and pt_BR strings for between_exclusive, contains_count, hetu, mimetype, portuguese_nif, public_domain_suffix and uploaded.use Datalogix\Validation\Rules\PortugueseNif;
public function rules(): array
{
return [
'nif' => ['required', 'string', new PortugueseNif()],
];
}
Rule objects in FormRequests. The idiomatic usage is instantiating rule classes and mixing them with Laravel's string rules. bail still short-circuits before the object rule runs, which matters for the file/identity rules where format checks are cheap but domain lookups are not.
Parameterised rules. Rules that take bounds/needles are constructed with arguments (new BetweenExclusive(1, 10), new ContainsCount('foo', 2)). Per the new docs, each rule maps its parameters to specific placeholders — :value, :values, :min, :max — so check the README table before authoring custom messages, otherwise you'll reference a placeholder the rule never replaces.
Custom messages. Override per-attribute without touching vendor files:
public function messages(): array
{
return [
'nif.portuguese_nif' => 'O NIF :value não é válido.',
'score.between_exclusive' => 'Deve estar entre :min e :max.',
];
}
Localisation. Set app.locale to pt_BR and the new translations are picked up automatically. If your app is English but validates Brazilian documents, you can still force pt_BR for a single validator instance via Validator::make($data, $rules, $messages, $attributes) plus ->setLocale().
Inline validation and testing. The rules are plain objects, so they work anywhere a rule instance is accepted:
$v = Validator::make(['file' => $upload], ['file' => [new Mimetype('image/png')]]);
$this->assertTrue($v->passes());
File rules. uploaded and mimetype expect an Illuminate\Http\UploadedFile. In tests use UploadedFile::fake() rather than passing a path string.
attribute message is not a breaking change. Laravel's internal validateAttribute() shadows the Respect rule, so that key was dead code. If you had customised it, your override was never read — move the wording into a normal messages() entry keyed by attribute.rule.validation.hetu mean a missing translation. Before 4.0.1 those seven rules had no en strings, so the message fell through to the key. If you still see raw keys after upgrading, you have a published (stale) lang file shadowing the package's — re-publish or delete the published copy.:min or :values shows up literally, either the rule doesn't populate that placeholder (consult the new docs table) or you're using a translated string that belongs to a different rule.public_domain_suffix does DNS work. It's fine in a FormRequest, painful in imports/seeders or list endpoints. Cache results or defer it to a queued job when validating in bulk.hetu (Finnish) and portuguese_nif are format-sensitive; uppercase and strip separators/whitespace in a prepareForValidation() hook rather than loosening the rule.$validator->errors()->getMessages() rather than the exception — you'll see the fully-expanded message and can immediately tell whether the failure came from the underlying Respect rule or from a translation gap.How can I help you explore Laravel packages today?