nielsjanssen / laravel-validation
Attribute-based validation for Laravel: declare rules on object properties and validate the object directly
Package info
github.com/NielsJanssen/laravel-validation
pkg:composer/nielsjanssen/laravel-validation
Requires
- php: ^8.5
- illuminate/support: ^13.15
- illuminate/validation: ^13.15
- tempest/reflection: ^3.10
Requires (Dev)
None
Suggests
- tempest/discovery: Pre-builds and caches rule plans at discovery time; without it rules are reflected on demand
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-12 15:13:49 UTC
README
Note
This is a read-only split mirror of the laravel-discovery monorepo. Please open issues and pull requests there.
laravel-validation
Attribute-based validation for Laravel. You declare validation rules directly on a class's properties or on a method's parameters, then validate in one call. The rules live next to the data they describe, so a data object carries its own validation contract.
use Illuminate\Support\Facades\Validator; use NielsJanssen\Laravel\Validation\Rule\{Email, Max, Min}; final class Registration { #[Min(2), Max(255)] public string $name = ''; #[Email] public ?string $email = null; } $registration = new Registration(); $registration->name = 'Anouk de Vries'; $registration->email = 'anouk@example.nl'; Validator::validateObject($registration);
Requirements
- PHP 8.5+
- Laravel 13+ (
illuminate/validation^13.15)
Installation
composer require nielsjanssen/laravel-validation
The service provider registers itself through package discovery. It replaces the bound validator factory with a
subclass that adds the object and method entry points, keeping the original factory's behaviour intact. There is
nothing to publish.
Documentation
- Validation: entry points, type inference, messages, conditional rules, nested objects, iterables, and custom rule attributes.
- Validation rules: every
attribute, the generic
#[Rule], andValidationContext. - GraphQL argument validation:
these attributes applied to
#[Query]and#[Mutation]parameters. - Full documentation for the rest of the monorepo.