PHPackages                             lullaby6/zschema - 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. lullaby6/zschema

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

lullaby6/zschema
================

Schema validations inspired by zod

v1.1.0(5mo ago)02MITPHPPHP &gt;=8.1

Since Oct 9Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/lullaby6/zschema)[ Packagist](https://packagist.org/packages/lullaby6/zschema)[ RSS](/packages/lullaby6-zschema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

ZSchema
=======

[](#zschema)

Table of contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Installation](#installation)
- [Basic usage](#basic_usage)
- [Types](#types)
- [Strings](#strings)
    - [Validations](#strings-validations)
    - [Transforms](#strings-transforms)
- [Numbers](#numbers)
    - [Types](#numbers-types)
    - [Validations](#numbers-validations)
    - [Transforms](#numbers-transforms)
- [Arrays](#arrays)
- [Collections](#collections)
- [Methods](#methods)
- [Messages](#messages)

Introduction
------------

[](#introduction)

Validates schemas and datatypes in a simple way, strongly inspired by [Zod](https://github.com/colinhacks/zod)

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

[](#installation)

```
composer require lullaby6/zschema
```

Basic usage
-----------

[](#basic-usage)

Creating a simple integer schema

```
require __DIR__ . '/vendor/autoload.php';

use Lullaby6\ZSchema\ZSchema;

// creating the integer schema
$int_schema = ZSchema::int();

// parsing
print_r($int_schema->safe_parse(5)); // output: ["success" => true]
print_r($int_schema->safe_parse("hello")); // output: ["success" => false, "message" => ...]
```

Creating a array schema

```
require __DIR__ . '/vendor/autoload.php';

use Lullaby6\ZSchema\ZSchema;

// creating user schema
$user_schema = ZSchema::array([
    "first_name" => ZSchema::string()->min_length(3)->required(),
    "last_name" => ZSchema::string()->min_length(3),
    "email" => ZSchema::string()->email()->required(),
]);

print_r($user_schema->safe_parse([
    "first_name" => "John",
    "last_name" => "Doe",
    "email" => "john@doe.com",
])); // output: ["success" => true]

print_r($user_schema->safe_parse([
    "first_name" => "John",
    "last_name" => "Doe",
    "email" => "johndoe.com",
])); // output: ["success" => false, "message" => "email is not a valid email"]
```

[Return to table of contents](#table-of-contents)

Types
-----

[](#types)

```
ZSchema::int()
ZSchema::float()
ZSchema::string()
ZSchema::bool()
ZSchema::array()
ZSchema::null()
```

[Return to table of contents](#table-of-contents)

Strings
-------

[](#strings)

Strings have many types of specific validations

### Strings validations

[](#strings-validations)

```
ZSchema::string()->required()
ZSchema::string()->not_empty()
ZSchema::string()->max_length() // the arg must be a integer, example: max_length(5)
ZSchema::string()->min_length() // the arg must be a integer, example: min_length(5)
ZSchema::string()->length() // the arg must be a integer, example: max_length(5)
ZSchema::string()->email()
ZSchema::string()->url()
ZSchema::string()->uuid()
ZSchema::string()->ipv4()
ZSchema::string()->ipv6()
ZSchema::string()->regex() // the arg must be a regex
ZSchema::string()->includes() // the arg must be a string, example: includes("http")
ZSchema::string()->not_includes() // the arg must be a string, example: not_includes("google")
ZSchema::string()->starts_with() // the arg must be a string, example: starts_with("http")
ZSchema::string()->not_starts_with() // the arg must be a string, example: not_starts_with("http")
ZSchema::string()->ends_with() // the arg must be a string, example: ends_with(".com")
ZSchema::string()->not_ends_with() // the arg must be a string, example: not_ends_with(".exe")
ZSchema::string()->date() // under review
ZSchema::string()->time() // under review
ZSchema::string()->datetime() // under review
```

### Strings transforms

[](#strings-transforms)

The transforms methods modify the value returned by the parse

```
ZSchema::string()->trim()
ZSchema::string()->to_lower_case()
ZSchema::string()->to_upper_case()
```

Example

```
echo ZSchema::string->to_lower_case()->parse("Hello World!") // output: "hello world!"
```

[Return to table of contents](#table-of-contents)

Numbers
-------

[](#numbers)

Validation and transformations methods work for both int and float

### Numbers types

[](#numbers-types)

```
ZSchema::int()
ZSchema::float()
```

### Numbers validations

[](#numbers-validations)

```
ZSChema::int()->required()
ZSChema::int()->not_empty()
ZSChema::int()->max()  // the arg must be a integer, example: max(100)
ZSChema::int()->min() // the arg must be a integer, example: min(0)
ZSChema::int()->positive()
ZSChema::int()->nonpositive()
ZSChema::int()->negative()
ZSChema::int()->nonnegative()
```

### Numbers transforms

[](#numbers-transforms)

The transforms methods modify the value returned by the parse

```
ZSchema::int()->to_max() // the arg must be a integer, example: to_max(100)
ZSchema::int()->to_min() // the arg must be a integer, example: to_min(0)
```

Example

```
echo ZSchema::int->to_max(25)->parse(10000) // output: 25
```

Arrays
------

[](#arrays)

The value of the array keys must be an instance of ZSchema, otherwise it will throw an error when creating a schema.

Example:

```
// BAD
ZSchema::array([
    "email" =>...
])

// GOOD
ZSchema::array([
    "email" => ZSchema::string()->email()
])
```

the value of the key can be any type of zschema

```
ZSchema::array([
    "day" => ZSchema::int()
])
```

[Return to table of contents](#table-of-contents)

Collections
-----------

[](#collections)

`ZSchema::collection()` allows you to validate an array of items where each item must match a specific schema. It returns an instance of Illuminate\\Support\\Collection, enabling the use of Laravel's powerful collection methods immediately after validation.

Example:

```
use Lullaby6\ZSchema\ZSchema;

// 1. Define the schema for a single item
$user_schema = ZSchema::array([
    "name" => ZSchema::string()->min_length(2),
    "role" => ZSchema::string()
]);

// 2. Define the collection schema wrapper
$users_list_schema = ZSchema::collection($user_schema);

// 3. Raw input data
$input = [
    ["name" => "Admin", "role" => "admin"],
    ["name" => "User",  "role" => "guest"],
];

// 4. Parse returns an Illuminate\Support\Collection
$collection = $users_list_schema->parse($input);

// Now you can use Laravel Collection methods!
$admins = $collection->where('role', 'admin');

print_r($admins->all());
// output: [ 0 => ["name" => "Admin", "role" => "admin"] ]
```

[Return to table of contents](#table-of-contents)

Methods
-------

[](#methods)

### parse

[](#parse)

The parse method executes the validations specified in the method value, if the validation fails it will throw an exception with an error message

```
ZSchema::int()->parse(5) // return 5
ZSchema::int()->parse("hola") // throws Error
```

### safe\_parse

[](#safe_parse)

Unlike the parse method, when the validation fails it will not throw an error, instead it will return an array with the message and the status of the validation.

```
ZSchema::int()->safe_parse(5) // return ["success" => true, "value" => 5]
ZSchema::int()->safe_parse("hola") // return ["success" => false, message => ..., "value" => "hola"]
```

### get\_validations()

[](#get_validations)

```
ZSchema::string()->email()->get_validations() // return ["email" => true]
```

### get\_transforms()

[](#get_transforms)

```
ZSchema::string()->to_lower_case()->get_transforms() // return ["to_lower_case" => true]
```

[Return to table of contents](#table-of-contents)

Messages
--------

[](#messages)

### Type error message

[](#type-error-message)

```
// by default
ZSchema::int()->safe_parse("world") // return ["sucess" => false, "message" => "world is not a valid int", ...]

// with custom type error message
ZSchema::int("The value is not a number")->safe_parse("world") // return ["sucess" => false, "message" => "The value is not a number", ...]
```

but for arrays the second argument is the message

```
$user_schema = ZSchema::array([
    "first_name" => ZSchema::string()->min_length(3)->required(),
    "last_name" => ZSchema::string()->min_length(3),
    "email" => ZSchema::string()->email()->required(),
], "The user value is not valid");
```

### Validations error messages

[](#validations-error-messages)

for validations it is a bit more of the same, in validations where no argument is required to validate, the argument will be the error message, if the validation method has an argument, then it will be the second argument

```
ZSchema::string()->email("The e-mail is not valid")->max_length(100, "The e-mail must not contain more than 100 characters")
```

[Return to table of contents](#table-of-contents)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance73

Regular maintenance activity

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

152d ago

### Community

Maintainers

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

---

Top Contributors

[![lullaby6](https://avatars.githubusercontent.com/u/78455830?v=4)](https://github.com/lullaby6 "lullaby6 (5 commits)")

---

Tags

phpphp-libraryschema

### Embed Badge

![Health badge](/badges/lullaby6-zschema/health.svg)

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

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[proengsoft/laravel-jsvalidation

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

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[sunspikes/clamav-validator

Custom Laravel 5 anti-virus validator for file uploads.

3651.8M3](/packages/sunspikes-clamav-validator)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

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

PHPackages © 2026

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