PHPackages                             sedlatschek/laravel-conditional-equals-validation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. sedlatschek/laravel-conditional-equals-validation

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

sedlatschek/laravel-conditional-equals-validation
=================================================

Additional rules for conditional equals validation

v1.0.0-beta.7(2y ago)03.1k[2 PRs](https://github.com/sedlatschek/laravel-conditional-equals-validation/pulls)MITPHPPHP ^8.1

Since Apr 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sedlatschek/laravel-conditional-equals-validation)[ Packagist](https://packagist.org/packages/sedlatschek/laravel-conditional-equals-validation)[ Docs](https://github.com/sedlatschek/laravel-conditional-equals-validation)[ RSS](/packages/sedlatschek-laravel-conditional-equals-validation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (11)Versions (11)Used By (0)

Laravel Conditional Equals Validation
=====================================

[](#laravel-conditional-equals-validation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/303fd8ff67e567a0df729f22340218d019ddf7f959c21c02ff89b5ebc8562a30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365646c6174736368656b2f6c61726176656c2d636f6e646974696f6e616c2d657175616c732d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sedlatschek/laravel-conditional-equals-validation)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8458d43f59b453f46e9633be40057d92c293a2da23d58e856f5d585cca0ae724/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7365646c6174736368656b2f6c61726176656c2d636f6e646974696f6e616c2d657175616c732d76616c69646174696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/sedlatschek/laravel-conditional-equals-validation/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ef5ccda642f17931aaf15aa25b10b85d4744a0f4728a1edb0bae9cb13042fd24/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7365646c6174736368656b2f6c61726176656c2d636f6e646974696f6e616c2d657175616c732d76616c69646174696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/sedlatschek/laravel-conditional-equals-validation/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8029b1cddebfe1dab8add5f91bf728078c27f36f0cc246f8f0ffce9b3ec45cfa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365646c6174736368656b2f6c61726176656c2d636f6e646974696f6e616c2d657175616c732d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sedlatschek/laravel-conditional-equals-validation)

This package provides additional validation rules for Laravel projects:

**Equals**

```
$request->validate([
    'a' => ['boolean', (new Equals(true))->if('b', false)],
    'b' => ['boolean']
]);
```

**NotEquals**

```
$request->validate([
    'a' => ['string', (new NotEquals('foo'))->ifAnyOf(['b', 'c'], 'bar')],
    'b' => ['string'],
    'c' => ['string'],
]);
```

See [Usage](#usage) for all possibilites! Also know that the native method `Rule::when` may be a better alternative to this package.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require sedlatschek/laravel-conditional-equals-validation
```

Usage
-----

[](#usage)

### If

[](#if)

Evaluate one other fields value.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->if('b', 'bar')],
    'b' => ['string'],
]);
```

### IfNot

[](#ifnot)

Evaluate one other fields value.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->ifNot('b', 'bar')],
    'b' => ['string'],
]);
```

### IfAllOf

[](#ifallof)

Evaluate if all of the given fields match the given value.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->ifAllOf(['b', 'c'], 'bar')],
    'b' => ['string'],
    'c' => ['string'],
]);
```

Example validation results:

```
// passes
$data = [
    'a' => 'foo',
    'b' => 'bar',
    'c' => 'bar',
];

// fails
$data = [
    'a' => 'x',
    'b' => 'bar',
    'c' => 'bar',
];

// passes
$data = [
    'a' => 'foo',
    'b' => 'bar',
    'c' => 'x',
];
```

### IfAnyOf

[](#ifanyof)

Evaluate if any of the given fields match the given value.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->ifAnyOf(['b', 'c'], 'bar')],
    'b' => ['string'],
    'c' => ['string'],
]);
```

Example validation results:

```
// passes
$data = [
    'a' => 'foo',
    'b' => 'bar',
    'c' => 'x',
];

// fails
$data = [
    'a' => 'x',
    'b' => 'bar',
    'c' => 'x',
];

// passes
$data = [
    'a' => 'foo',
    'b' => 'x',
    'c' => 'x',
];
```

### IfNoneOf

[](#ifnoneof)

Evaluate if none of the given fields match the given value.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->ifNoneOf(['b', 'c'], 'bar')],
    'b' => ['string'],
    'c' => ['string'],
]);
```

Example validation results:

```
// passes
$data = [
    'a' => 'foo',
    'b' => 'x',
    'c' => 'x',
];

// fails
$data = [
    'a' => 'x',
    'b' => 'x',
    'c' => 'x',
];

// passes
$data = [
    'a' => 'foo',
    'b' => 'x',
    'c' => 'bar',
];
```

### Combined

[](#combined)

All of the above conditions can be chained. The connection between each condition is seen as an `and` operator.

```
$request->validate([
    'a' => ['string', (new Equals('foo'))->if('b', 'bar')->ifAnyOf(['c', 'd'], false)->ifAllOf(['e', 'f', 'g'], 1),
    'b' => ['string'],
    'c' => ['boolean'],
    'd' => ['boolean'],
    'e' => ['integer'],
    'f' => ['integer'],
    'g' => ['integer'],
]);
```

Example validation results:

```
// passes
$data = [
    'a' => 'foo',
    'b' => 'bar',
    'c' => true,
    'd' => false,
    'e' => 1,
    'f' => 1,
    'g' => 1,
];

// fails
$data = [
    'a' => 'x',
    'b' => 'bar',
    'c' => true,
    'd' => false,
    'e' => 1,
    'f' => 1,
    'g' => 1,
];

// passes
$data = [
    'a' => 'x',
    'b' => 'bar',
    'c' => true,
    'd' => false,
    'e' => 1,
    'f' => 1,
    'g' => 2,
];

// passes
$data = [
    'a' => 'x',
    'b' => 'x',
    'c' => true,
    'd' => false,
    'e' => 1,
    'f' => 1,
    'g' => 1,
];

// passes
$data = [
    'a' => 'x',
    'b' => 'x',
    'c' => true,
    'd' => true,
    'e' => 1,
    'f' => 1,
    'g' => 1,
];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Simon Sedlatschek](https://github.com/sedlatschek)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~21 days

Total

7

Last Release

1028d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b1b2b23323636313426acffaa6e749f0392fd1fc7d845117adb37aa54d817fd?d=identicon)[sedlatschek](/maintainers/sedlatschek)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")[![sedlatschek](https://avatars.githubusercontent.com/u/58665536?v=4)](https://github.com/sedlatschek "sedlatschek (1 commits)")

---

Tags

laravelvalidationlaravelvalidationequalifequalssedlatschek

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sedlatschek-laravel-conditional-equals-validation/health.svg)

```
[![Health](https://phpackages.com/badges/sedlatschek-laravel-conditional-equals-validation/health.svg)](https://phpackages.com/packages/sedlatschek-laravel-conditional-equals-validation)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[galahad/laravel-addressing

Laravel package providing addressing functionality

70316.6k](/packages/galahad-laravel-addressing)[orkhanahmadov/laravel-zip-validator

Laravel ZIP file content validator

12424.9k](/packages/orkhanahmadov-laravel-zip-validator)[yorcreative/laravel-argonaut-dto

Argonaut is a lightweight Data Transfer Object (DTO) package for Laravel that supports nested casting, recursive serialization, and validation out of the box. Ideal for service layers, APIs, and clean architecture workflows.

1062.8k1](/packages/yorcreative-laravel-argonaut-dto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
