Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Validation Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Install with composer require datalogix/laravel-validation (Laravel package discovery registers the service provider; no manual wiring needed).
  2. Look at the rule classes first — each rule is a small object wrapping the corresponding Respect Validation rule (Hetu, PortugueseNif, Mimetype, Uploaded, BetweenExclusive, ContainsCount, PublicDomainSuffix, …). The class constructor signature tells you what parameters it accepts.
  3. Check the language files shipped with the package if you care about error copy — v4.0.1 added en and pt_BR strings for between_exclusive, contains_count, hetu, mimetype, portuguese_nif, public_domain_suffix and uploaded.
  4. First real use case: swap a hand-rolled regex in a FormRequest for the packaged rule:
use Datalogix\Validation\Rules\PortugueseNif;

public function rules(): array
{
    return [
        'nif' => ['required', 'string', new PortugueseNif()],
    ];
}

Implementation Patterns

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.

Gotchas and Tips

  • The removed 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.
  • Raw keys like 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.
  • Unreplaced placeholders are a signal, not a silent failure. If :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.
  • Normalise before validating identity numbers. hetu (Finnish) and portuguese_nif are format-sensitive; uppercase and strip separators/whitespace in a prepareForValidation() hook rather than loosening the rule.
  • Debugging tip: when a rule fails unexpectedly, dump $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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core