PHPackages                             laraantunes/validare - 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. laraantunes/validare

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

laraantunes/validare
====================

A simple-to-use validation library.

1.0.2(3y ago)0181GPL-3.0-or-laterPHP

Since Apr 9Pushed 11mo agoCompare

[ Source](https://github.com/laraantunes/validare)[ Packagist](https://packagist.org/packages/laraantunes/validare)[ RSS](/packages/laraantunes-validare/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (1)

Validare
========

[](#validare)

A simple to use validation library.

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

[](#installation)

`composer require laraantunes/validare`

Basic Usage
-----------

[](#basic-usage)

Create a class and use the `\Validare\Bind` trait and add the rules by the validate() method:

```
class MyClass {
    use \Validare\Bind;

    public $myField;

   /**
    * Validare includes the rules() method that is called
    * before the proper validation to bind the field
    * validations
    */
   public function rules() {
       $this->validate('myField', \Validare\Rule::REQUIRED);
   }
}

$myObj = new MyClass();
echo $myObj->valid(); // It'll return false

// It'll return an array with all the validation errors found
var_dump($myObj->validationErrors());
```

### The validate() method

[](#the-validate-method)

The `valid()` method is an alias for `validate()`, without any parameter. This way, it'll run the validation for the object. If `validate()` is called with parameters, it'll add a validation for the field passed as the first parameter with the rules passed as the other parameters:

```
// Adds a REQUIRED validation for myField:
$myObj->validate('myField', \Validare\Rule::REQUIRED);

// You may pass more than one rule when calling validate()!
$myObj->validate('myField',  [\Validare\Rule::LESS_OR_EQUALS => 5], [\Validare\Rule::MORE => 3]);

// When passing a value that must be compared, pass the rule as an array:
$myObj->validate('myField', [\Validare\Rule::LENGTH => 4]);

// You need to use the full array syntax if you need to pass a custom rule name for errors:
$myObj->validate('myField', [
    'rule' => \Validare\Rule::MAX_LENGTH,
    'compare' => 5,
    'ruleName' => 'My Rule Name',
]);

// You may also pass closures as rules!
$myObj->validate('myField', function($value){
    return $value->value == 5;
});

// And even with 'use' clause:
$myObj->validate('myField', function($value) use ($customValue){
    return $value->value == $customValue;
});

// And if you need to handle all the \Validare\Rule object, you may pass a new object:
$myObj->validate('myField', new \Validare\Rule(1, \Validare\Rule::EQUALS, 1));

// if you need to use a callback after validate, use a \Validate\Rule object:
$myObj->validate(
    'myField',
    new \Validare\Rule(
        $value,
        \Validare\Rule::IS_STRING,
        null,
        null,
        function($success){
            if ($success) {
                // Do something!
            }
        }
    )
);
```

### The default Rules

[](#the-default-rules)

*Validare* comes with many default useful rules and more still will come. All them are valid as constants of the `\Validare\Rule` class:

- REQUIRED
- POSITIVE
- NEGATIVE
- LENGTH
- MIN\_LENGTH
- MAX\_LENGTH
- MORE
- LESS
- MORE\_OR\_EQUALS
- LESS\_OR\_EQUALS
- EQUALS
- NOT\_EQUALS
- IS\_ARRAY
- IS\_STRING
- IS\_NUMERIC
- IS\_A
- COUNT\_EQUALS
- COUNT\_MORE
- COUNT\_LESS
- COUNT\_MORE\_EQUALS
- COUNT\_LESS\_EQUALS
- HAS\_ATTRIBUTE
- HAS\_ATTRIBUTE\_VALUE

### The Assert class

[](#the-assert-class)

If you need to validate a specific value, you may use the `\Validare\Assert` class. It has 2 basic methods, a magic method that calls the default rules dynamically and a `value()` method that validates something with the same syntax that the `Validare\Bind::validate()` method:

```
    // Magic Calls for default rules:
    \Validare\Assert::required('my test value'); // Returns true
    \Validare\Assert::length('test', 5); // Returns false

    // Default assert (rules may be called as the same as \Validare\Bind::validate() method):
    \Validare\Assert::value('Valid', \Validare\Rule::REQUIRED); // Returns true
    \Validare\Assert::value(
        2,
        [\Validare\Rule::LESS_OR_EQUALS => 5],
        [\Validare\Rule::MORE => 3]
    ); // Returns false

    // If you need to check if an object has an attribute defined, use 'has_attribute' rule:
    \Validare\Assert::has_attribute($obj, 'test');

    // And if you need to check a value of an object, use 'has_attribute_value' rule, with an
    // array on compareValue:
    \Validare\Assert::has_attribute_value($obj, ['test' => 'wololo']);
```

Tests
-----

[](#tests)

Tests are under `test/` folder using PHPUnit.

Contributing
------------

[](#contributing)

Fell free to create pull requests with new rules, bug fixing and suggestions! &lt;3

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Every ~716 days

Total

3

Last Release

1163d ago

### Community

Maintainers

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

---

Top Contributors

[![laraantunes](https://avatars.githubusercontent.com/u/24675306?v=4)](https://github.com/laraantunes "laraantunes (10 commits)")

---

Tags

phpphp72validationvalidation-libraryvalidator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laraantunes-validare/health.svg)

```
[![Health](https://phpackages.com/badges/laraantunes-validare/health.svg)](https://phpackages.com/packages/laraantunes-validare)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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