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(6mo ago)12MITPHPPHP &gt;=8.1

Since Oct 9Pushed 1mo ago1 watchersCompare

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

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)

A library to validate shemas and data types inspired by [Zod](https://github.com/colinhacks/zod) from TypeScript.

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

36

—

LowBetter than 79% of packages

Maintenance81

Actively maintained with recent releases

Popularity4

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

199d ago

### Community

Maintainers

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

---

Top Contributors

[![lullaby6](https://avatars.githubusercontent.com/u/78455830?v=4)](https://github.com/lullaby6 "lullaby6 (7 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

[illuminate/validation

The Illuminate Validation package.

18838.2M1.7k](/packages/illuminate-validation)

PHPackages © 2026

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