PHPackages                             riley19280/laravel-rules-to-schema - 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. riley19280/laravel-rules-to-schema

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

riley19280/laravel-rules-to-schema
==================================

Parse Laravel validation rules into a Json Schema

v0.5.0(1y ago)281[4 PRs](https://github.com/Riley19280/laravel-rules-to-schema/pulls)MITPHPPHP ^8.2CI passing

Since Sep 5Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Riley19280/laravel-rules-to-schema)[ Packagist](https://packagist.org/packages/riley19280/laravel-rules-to-schema)[ Docs](https://github.com/riley19280/laravel-rules-to-schema)[ GitHub Sponsors]()[ RSS](/packages/riley19280-laravel-rules-to-schema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (6)Used By (0)

Laravel Rules to Schema
=======================

[](#laravel-rules-to-schema)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a59e8418d82fcc193120a84ce2377dc32781c93831f09dbb58ddca745e9ae58f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696c657931393238302f6c61726176656c2d72756c65732d746f2d736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riley19280/laravel-rules-to-schema)[![GitHub Tests Action Status](https://camo.githubusercontent.com/99169216a170a8fb87634bfd03b6eedeead9102966ec440f96457d2861730489/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72696c657931393238302f6c61726176656c2d72756c65732d746f2d736368656d612f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/riley19280/laravel-rules-to-schema/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c43169b16da780dc3862223139c41bada8e78e4434dd69f73009e954a1e88e14/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72696c657931393238302f6c61726176656c2d72756c65732d746f2d736368656d612f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/riley19280/laravel-rules-to-schema/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a5e6aadc7dbb407e1dd4269cc14656460ae5ff71345f67c27028102f484bf6a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696c657931393238302f6c61726176656c2d72756c65732d746f2d736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riley19280/laravel-rules-to-schema)

Create a json schema for your Laravel rules

Prerequisites
-------------

[](#prerequisites)

It is recommended to use `FormRequest` classes in your application to use this package. This allows for easy extraction of rule objects to pass them into this package.

You can still use this package just by passing in an array of rules, but that is a but more cumbersome.

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

[](#installation)

You can install the package via composer:

```
composer require riley19280/laravel-rules-to-schema
```

And publish the config file with:

```
php artisan vendor:publish --tag="laravel-rules-to-schema-config"
```

Usage
-----

[](#usage)

```
use \Illuminate\Foundation\Http\FormRequest;

$schema = LaravelRulesToSchema::parse(FormRequest|array $rules): FluentSchema

$schema->compile(); // Returns an array representation of the json schema
```

Customization
-------------

[](#customization)

### JSON Schema Representation

[](#json-schema-representation)

This package relies on [riley19280/fluent-json-schema](https://github.com/riley19280/fluent-json-schema) to build and represent JSON schemas. For details on how to use and configure the objects returned from the rule parser, please see the [documentation](https://github.com/riley19280/fluent-json-schema) for that package.

### Registering schemas for custom rules

[](#registering-schemas-for-custom-rules)

JSON Schema definitions for custom rules can be registered in the config file by providing the rule name or class name.

The type can be any of the simple JSON schema types (array, boolean, integer, null, number, object, string). If a more complex type is required, you can provide the class name that implements `LaravelRulesToSchema\Contracts\HasJsonSchema`

```
// config/rules-to-schema.php

'custom_rule_schemas' => [
    // \CustomPackage\CustomRule::class => \Support\CustomRuleSchemaDefinition::class,
    // \CustomPackage\CustomRule::class => 'string',
    // \CustomPackage\CustomRule::class => ['null', 'string'],
],
```

### Extending the rule parser

[](#extending-the-rule-parser)

Should you want to further customize or tweak how rules are parsed, additional parsers can be added in the config file. Each parser is run for each rule in the order it is defined in the config file. Custom parsers must implement the `LaravelRulesToSchema\Contracts\RuleParser` interface.

```
// config/rules-to-schema.php

'parsers' => [
    ...
    \CustomPackage\CustomParser::class,
],
```

### Tools for package developers

[](#tools-for-package-developers)

If your package contains a custom rule, you can provide the types as part of the package as well.

In a service provider you can use the following methods to programmatically register a rule or parser:

```
LaravelRulesToSchema::registerCustomRuleSchema(CustomRule::class, CustomRuleSchemaDefinition::class);
LaravelRulesToSchema::registerParser(CustomParser::class);
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Riley Aven](https://github.com/Riley19280)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance67

Regular maintenance activity

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

614d ago

### Community

Maintainers

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

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![Riley19280](https://avatars.githubusercontent.com/u/14127031?v=4)](https://github.com/Riley19280 "Riley19280 (4 commits)")

---

Tags

laraveljson-schemalaravel ruleRiley Avenlaravel-rules-to-schemaparse rule

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/riley19280-laravel-rules-to-schema/health.svg)

```
[![Health](https://phpackages.com/badges/riley19280-laravel-rules-to-schema/health.svg)](https://phpackages.com/packages/riley19280-laravel-rules-to-schema)
```

###  Alternatives

[sunchayn/nimbus

A Laravel package providing an in-browser API client with automatic schema generation, live validation, and built-in authentication with a touch of Laravel-tailored magic for effortless API testing.

29428.0k](/packages/sunchayn-nimbus)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ziming/laravel-zxcvbn

Zxcvbn Password validation rule for Laravel

3056.7k](/packages/ziming-laravel-zxcvbn)[laravel-validation-rules/phone

Validate that a phone number is in the correct format

69355.5k](/packages/laravel-validation-rules-phone)

PHPackages © 2026

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