PHPackages                             nelson-dominici/slimgry - 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. nelson-dominici/slimgry

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

nelson-dominici/slimgry
=======================

Slimgry is a validation middleware for the Slim framework, with a validation syntax similar to Laravel.

1.0.0(2y ago)13161MITPHPPHP ^8.2

Since Mar 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Nelson-Dominici/Slimgry)[ Packagist](https://packagist.org/packages/nelson-dominici/slimgry)[ RSS](/packages/nelson-dominici-slimgry/feed)WikiDiscussions main Synced 3w ago

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

 [![Descrição da Imagem](https://private-user-images.githubusercontent.com/89428967/305746056-4abb20fb-269f-46ac-84bb-a115ad4a80f8.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODIzODYwOTcsIm5iZiI6MTc4MjM4NTc5NywicGF0aCI6Ii84OTQyODk2Ny8zMDU3NDYwNTYtNGFiYjIwZmItMjY5Zi00NmFjLTg0YmItYTExNWFkNGE4MGY4LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA2MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNjI1VDExMDk1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ5ZWQ1MTQ4ZWMzMWUxODJlNGI3NTYzZmE3ZGQxODkxMTdjNDljZjJkMjMzOGZlMDNhMmQ3NmQ0YzA4MDhhMTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRmpwZWcifQ.OOh0FnyIK_o5qejMzMNTf9v6ff6qSyBOhDHb1Kn-C1s)](https://private-user-images.githubusercontent.com/89428967/305746056-4abb20fb-269f-46ac-84bb-a115ad4a80f8.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODIzODYwOTcsIm5iZiI6MTc4MjM4NTc5NywicGF0aCI6Ii84OTQyODk2Ny8zMDU3NDYwNTYtNGFiYjIwZmItMjY5Zi00NmFjLTg0YmItYTExNWFkNGE4MGY4LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA2MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNjI1VDExMDk1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ5ZWQ1MTQ4ZWMzMWUxODJlNGI3NTYzZmE3ZGQxODkxMTdjNDljZjJkMjMzOGZlMDNhMmQ3NmQ0YzA4MDhhMTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRmpwZWcifQ.OOh0FnyIK_o5qejMzMNTf9v6ff6qSyBOhDHb1Kn-C1s)
 [![License: MIT](https://camo.githubusercontent.com/1ef54966e942fd44206edc32d799285649d9b753c23f344826f5743ff9a5da63/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d77686974652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1ef54966e942fd44206edc32d799285649d9b753c23f344826f5743ff9a5da63/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d77686974652e7376673f7374796c653d666c61742d737175617265) [![Requires PHP ^8.2](https://camo.githubusercontent.com/ac56c87d3027c51e0fb2895653ceb3f193fea477cc34031d2bd09d6b0c9a23c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3733373761633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ac56c87d3027c51e0fb2895653ceb3f193fea477cc34031d2bd09d6b0c9a23c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3733373761633f7374796c653d666c61742d737175617265) [![Requires Slim Framework >=   4](https://camo.githubusercontent.com/d7070f9c5ec2cc3577d7d6a29092835f00d0d5a88cb3c66308e6be586baf3e09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536c696d5f4672616d65776f726b2d253345253344253230342d3644394333433f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d7070f9c5ec2cc3577d7d6a29092835f00d0d5a88cb3c66308e6be586baf3e09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536c696d5f4672616d65776f726b2d253345253344253230342d3644394333433f7374796c653d666c61742d737175617265)

### Slimgry is a **validation middleware** for the [Slim framework](https://www.slimframework.com/), which validates the request body, with validation syntax similar to [Laravel](https://laravel.com/docs/10.x/validation).

[](#slimgry-is-a-validation-middleware-for-the-slim-framework-which-validates-the-request-body-with-validation-syntax-similar-to-laravel)

Install
-------

[](#install)

```
composer require nelson-dominici/slimgry
```

Usage
-----

[](#usage)

To add validations to a route, add the `NelsonDominici\Slimgry\Slimgry` middleware with the validations in the constructor.
If any validation method fails, an `NelsonDominici\Slimgry\Exceptions\ValidationMethodException` exception will be thrown.

```
use NelsonDominici\Slimgry\Slimgry;

$app->post('/api/auth', [AuthController::class, 'login'])->add(new Slimgry(
    [
        'email' => ['required','email','trim','string','min:3','max:100'],
        'password' => ['required','trim','string','min:6','max:100']
    ]
));
```

You can also use `|`.

```
[
    'email' => 'required|email|trim|string|min:3|max:100',
    'password' => 'required|trim|string|min:6|max:100'
]
```

Validating nested fields
------------------------

[](#validating-nested-fields)

You can use "dot notation" to validate nested fields, example:

```
[
    'users.adm.email' => ['required','email','trim','string','min:3','max:100'],
    'users.adm.password' => ['required','trim','string','min:6','max:100'],
]
```

Adding custom message when validation method fails
--------------------------------------------------

[](#adding-custom-message-when-validation-method-fails)

Add a second array in the Slimgry class to store custom messages, choose which field the message refers to along with a "dot" and the validation method that failed.

```
use NelsonDominici\Slimgry\Slimgry;

$app->post('/api/auth', [AuthController::class, 'auth'])->add(new Slimgry(
    [
        'email' => ['required','email','trim','string','min:3','max:100'],
        'password' => ['required','trim','string','min:6','max:100']
    ],
    [
        'email.email' => 'We need a valid email.',
        'password.required' => 'We need your password.'
    ]
));
```

Validation Methods List
-----------------------

[](#validation-methods-list)

Validation MethodFunctionAttention!arrayThe field under validation must be a PHP `array`booleanThe field under validation must be a `boolean`Only `true` or `false` is acceptedemailThe field under validation must be a valid `email`[filter\_var()](https://www.php.net/manual/en/function.filter-var.php) is used with `FILTER_VALIDATE_EMAIL`gt:valueThe field under validation must be greater than a `numeric` valueOnly `numeric` values are validatedgte:valueThe field under validation must be greater than or equal to a `numeric` valueOnly `numeric` values are validatedintegerThe field under validation must be an `integer`ipThe field under validation must be an IP address[filter\_var()](https://www.php.net/manual/en/function.filter-var.php) is used with `FILTER_VALIDATE_IP`max:valueThe field under validation must have a maximum number of `elements`Only `arrays`, `strings`, and `numeric` values are validatedmin:valueThe field under validation must have a minimum number of `elements`Only `arrays`, `strings`, and `numeric` values are validatednullableThe field under validation may be `null`numericThe field under validation must be `numeric`presentThe field under validation must exist in request bodyregex:patternThe field under validation must match the given regular expressionrequiredThe field under validation must be present in request body and not "empty"Values considered "empty" are `null`, `empty string` and `empty array`size:valueThe field under validation must have a specific number of `elements`Only `arrays`, `strings`, and `numeric` values are validatedstringThe field under validation must be a `string`trimRemove white space from The field under validationuuidThe field under validation must be a valid universally unique identifier (UUID) in 4 version

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

846d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1368704a3e88e854a12a76154ba3043a2c0f086105f19c78ec46916852dc7fc?d=identicon)[Nelson-Dominici](/maintainers/Nelson-Dominici)

---

Top Contributors

[![Nelson-Dominici](https://avatars.githubusercontent.com/u/89428967?v=4)](https://github.com/Nelson-Dominici "Nelson-Dominici (323 commits)")

---

Tags

packagephpslim-frameworkvalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nelson-dominici-slimgry/health.svg)

```
[![Health](https://phpackages.com/badges/nelson-dominici-slimgry/health.svg)](https://phpackages.com/packages/nelson-dominici-slimgry)
```

###  Alternatives

[phlak/directory-lister

PHP directory lister

2.5k1.4k](/packages/phlak-directory-lister)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[brandembassy/slim-nette-extension

19198.2k](/packages/brandembassy-slim-nette-extension)[egroupware/openid

EGroupware OpenID Connect / OAuth2 server

1227.4k3](/packages/egroupware-openid)[duxweb/dux-lite

The lightweight framework based on slim php

161.0k9](/packages/duxweb-dux-lite)

PHPackages © 2026

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