
phpstan-laravel-validation
Laravel validation is not a typed data boundary. This extension recovers
sound structural types for successful validated() output from statically
resolvable rule sets.
The inferred type may be broader than a rule name suggests because Laravel usually preserves the original native value. See Laravel Validation and Type Safety for the evidence.
Caution
For new type-conscious code, prefer a boundary with an explicit, normalized output contract. This library is a mitigation for existing Laravel validation, not an endorsement of that design.
Start here
$data = \Illuminate\Support\Facades\Validator::make($request->all(), [
'person' => 'required|array',
'person.*.email' => 'required|string|email|unique:users',
'person.*.first_name' => 'required|string',
'person.*.age' => 'required|integer|string',
])->validated();
\PHPStan\dumpType($data);
// array{person: array<int|string, array{
// email: non-empty-string,
// first_name: string,
// age: numeric-string
// }>}
- Install and run a first analysis. Getting Started
- Understand why a type is broader than the rule name. Understanding Inferred Types
- Look up a rule, builder, or configuration key. Configuration, Validation Rules, Rule Builders
The 0.1 line is an experimental public release. Compatibility and known limitations are in Getting Started and Limitations.