PHPackages                             amirhs712/rule-builder - 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. amirhs712/rule-builder

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

amirhs712/rule-builder
======================

Validation Rule Builder for Laravel

1.0.0(5y ago)3336MITPHPPHP &gt;=7.1

Since Oct 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/amirhs712/nope)[ Packagist](https://packagist.org/packages/amirhs712/rule-builder)[ RSS](/packages/amirhs712-rule-builder/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Nope
====

[](#nope)

[![Latest Stable Version](https://camo.githubusercontent.com/753f90e2aad5c6faf1b1571fa615ff3d44f987599126a06034f43808242975ea/68747470733a2f2f706f7365722e707567782e6f72672f616d697268733731322f72756c652d6275696c6465722f76)](https://packagist.org/packages/amirhs712/rule-builder) [![Total Downloads](https://camo.githubusercontent.com/0a55e0b3052e440dc77ecb63c35a32c3560e82e8908c75b00c52d60995b7ac07/68747470733a2f2f706f7365722e707567782e6f72672f616d697268733731322f72756c652d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/amirhs712/rule-builder) [![License](https://camo.githubusercontent.com/2f5854e3eb132b021c50d90e128e4b532be1630a9378d8acece0f707ad92e6df/68747470733a2f2f706f7365722e707567782e6f72672f616d697268733731322f72756c652d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/amirhs712/rule-builder)

Nope is a validation rule builder for laravel inspired by `Yup` for javascript.

With `Nope` you can generate rules more fluently, I've also copied rules description from laravel official website and hard coded them into Nope, so you can have access to documentations easily.

Some functionalities have been extended for validation rules, for example you can pass Carbon instances to date validation rules like `after`.

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

[](#installation)

Require this package with composer using the following command:

```
   composer require amirhs712/rule-builder

```

Usage
-----

[](#usage)

I recommend using `nope()` global helper for warning-free and complete ide-inspection. Also you can use `Amirhs712\RuleBuilder\Nope` class instead.

```
   $rules = [
        'username' => nope()->required()->string()->max(30)->get(), //[required,string,max:30]

        'password' => Nope::required()->stringOf(30)->confirmed()->get() //[required,string,confirmed,max:30]
];
```

We use `get()` to get output as an array, alternatively you can use `toString()`to return the output as a pipe separated string.

- `toString` and `get` support a required status ranging from `-2` to `1`.
    - 1 =&gt; call `required` rule
    - 0 =&gt; do nothing (default)
    - -1 =&gt; call `sometimes` rule
    - -2 =&gt; call `sometimes` &amp; `nullable` rules

```
    $rules = [
        'username' => nope()->stringOf(30)->toString(1), //string|max:30|required

        'password' => nope()->stringOf(30)->toString(-2) //string|max:30|sometimes|nullable
];
```

### Date Rules with Carbon

[](#date-rules-with-carbon)

You can pass a carbon instance to the following date rules: `after`, `afterOrEqual`, `dateEquals`,`before`, `beforeOrEqual`

```
    $rules = [
        'date' => nope()->after('today')->get(),

        'another_date' => nope()->afterOrEqual(now()->addMonth())->get(),
];
```

### Min / Max Helpers

[](#min--max-helpers)

These methods allow you to set min and / or max arguments manually.

```
Rule::activeUrl($max)
    ->alpha($min, $max)
    ->alphaDash($min, $max)
    ->alphaNum($min, $max)
    ->array($min, $max)
    ->file($max)
    ->image($max)
    ->integer($min, $max)
    ->json($max)
    ->numeric($min, $max)
    ->string($min, $max)
    ->url($max);
```

### Raw rules

[](#raw-rules)

You can use `raw(string|array)` to add raw string rules or validation objects.

```
    $rules=[
        'field1' => nope()->raw('string|max:30')->get(),
        'field2' => nope()->raw(['string', 'max:30'])->get(),
        'field3' => nope()->raw(new ValidationObject)->get(),
        'field4' => nope()->raw([new ValidationObject, new AnotherObject])->get(),
        'field5' => nope()->raw('string')->raw('max')->get(),
];
```

- Note: You cannot call `toString` method if you have validation objects. Doing so will result in an error.

### Conditional rules

[](#conditional-rules)

You can use `when` method to add rules conditionally.

```
nope()->when($conditionIsMet, function(Nope $nope){
    $nope->max(100);
});
```

### Laravel constraint builders

[](#laravel-constraint-builders)

`in`, `notIn`, `dimensions`, `exists`, `unique` methods support both their relative constraint builders and, their default values.

```

$rules = [
    'image1' => nope()->dimensions(['width' => 300, 'height' => 300])->get(),

    'image2' => nope()->dimensions(Rule::dimensions()->width(300)->height(300))->get(),
];
```

### Templates

[](#templates)

You can build and define your own rule templates.

**Coming soon!**

### Undefined methods

[](#undefined-methods)

Right now there are no limitations for method calls (I could not find a reason to do so), for example you can do

```
nope()->myCustomExtendedRule($arg1, $arg2,...)->get(); //Results in: ["my_custom_extended_rule:$arg1, $arg2,..."]
```

Alternatives
------------

[](#alternatives)

You can check [this package](https://github.com/timacdonald/rule-builder) as an alternative, I've implemented some ideas from this package and merged them into my own solution.

Feedback
--------

[](#feedback)

Please feel free to open up an issue, or a Pull Request if you have any suggestions.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.3% of commits — single point of failure

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

Unknown

Total

1

Last Release

2027d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcb2bfa023d28da4663e80567dddea2cb7516c131dde7d5f749498edafb43ee0?d=identicon)[amirhs712](/maintainers/amirhs712)

---

Top Contributors

[![amirhos712](https://avatars.githubusercontent.com/u/22843335?v=4)](https://github.com/amirhos712 "amirhos712 (9 commits)")[![amirhs712](https://avatars.githubusercontent.com/u/52674066?v=4)](https://github.com/amirhs712 "amirhs712 (5 commits)")

---

Tags

laravelvalidationrulerule-builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amirhs712-rule-builder/health.svg)

```
[![Health](https://phpackages.com/badges/amirhs712-rule-builder/health.svg)](https://phpackages.com/packages/amirhs712-rule-builder)
```

###  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)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)

PHPackages © 2026

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