Laravel 13.36 New Published on

Validation rules without parameter strings

Every validation rule now has its Rule:: method: the editor completes them, and a value that contains a comma is no longer cut in two.

Topics covered: Validation

New in Laravel 13.36. Some rules already had their method, like Rule::in() or Rule::unique(). The others could only be written as strings: 'url:https', 'uuid:4', 'required_without:email'. The editor does not complete them, a typo only shows at runtime, and the parameters are split on commas.

Since Laravel 13.36

Every rule has its Rule:: method:

use Illuminate\Validation\Rule;

$request->validate([
    'phone' => [Rule::requiredWithout('email')],
    'website' => ['nullable', Rule::url()->protocols(['https'])],
    'device' => [Rule::uuid()->version(4)],
    'tags.*' => [Rule::distinct()->ignoreCase()],
    'password' => ['required', Rule::confirmed()],
]);

Rules that take field names or values pass them whole: a value that contains a comma is no longer cut.

Laravel 13.37 adds strict: true to Rule::numeric(), the equivalent of numeric:strict: a JSON number passes, the text "10" does not.

Your task

POST /api/registrations validates a registration to a conference. All its rules work, except one: the "Pro, with lunch" plan must require allergens_read, and requires nothing. The request in the "Requests" tab shows it.

Rewrite with Rule:: every rule that takes parameters. The other tests check that none of them changes behaviour along the way.

Where the feature comes from: the original pull request.