Skip to content

Conversation

@KIKOmanasijev
Copy link
Contributor

@KIKOmanasijev KIKOmanasijev commented Jul 28, 2025

This PR introduces the doesnt_contain validation rule, which ensures an array does not contain any of the specified values. It complements the existing contains rule, which validates that an array includes all specified values.

Like contains, doesnt_contain supports a string-like format (e.g., 'field' => 'doesnt_contain:spam') and is implemented in Illuminate\Validation\Validator with a corresponding DoesntContain rule class.

How to use it

Passing example

use Illuminate\Support\Facades\Validator;

// ✅ passes
$validator = Validator::make(
    ['tags' => ['php', 'laravel', 'symfony']],
    ['tags' => 'required|array|doesnt_contain:javascript']
);

Failing example

use Illuminate\Support\Facades\Validator;

// ❌ fails
$validator = Validator::make(
    ['tags' => ['php', 'laravel', 'symfony']],
    ['tags' => 'required|array|doesnt_contain:php']
);

Passing example using Rule class syntax:

use Illuminate\Support\Facades\Validator;

// ✅ passes
$validator = Validator::make(
    ['tags' => ['php', 'laravel', 'symfony']],
    [
        'tags' => [
            'required',
            'array',
            Rule::doesntContain('javascript')
        ]
    ]
);

@KIKOmanasijev KIKOmanasijev changed the title [12.x]: Add 'does not contain' validation rule [12.x]: Add 'doesntContain' validation rule Jul 28, 2025
@taylorotwell taylorotwell merged commit ad13858 into laravel:12.x Jul 30, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants