PHPackages                             romegasoftware/laravel-schema-generator - 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. romegasoftware/laravel-schema-generator

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

romegasoftware/laravel-schema-generator
=======================================

Generate TypeScript Zod validation schemas from Laravel validation rules

v1.0.10(1mo ago)288.2k↓37%2[1 PRs](https://github.com/romegasoftware/laravel-schema-generator/pulls)MITPHPPHP ^8.1

Since Sep 16Pushed 1mo agoCompare

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

READMEChangelog (10)Dependencies (14)Versions (19)Used By (0)

Laravel Schema Generator
========================

[](#laravel-schema-generator)

Generate TypeScript Schema validation schemas from your Laravel validation rules. This package supports Laravel FormRequest classes, Spatie Data classes, and custom validation classes through an extensible architecture.

It will generate Zod schema out of the box, but can be extended for different schema generators.

Features
--------

[](#features)

- 🚀 **Zero Dependencies** - Works with vanilla Laravel
- 📦 **Smart Package Detection** - Automatically detects and uses installed packages
- 🎯 **Multiple Validation Sources** - FormRequests, Spatie Data classes, custom extractors
- 🔧 **Flexible Configuration** - Customize output paths, formats, and integration settings
- 🧩 **Highly Extensible** - Custom extractors and type handlers with priority system

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

[](#installation)

```
composer require romegasoftware/laravel-schema-generator
```

Ensure Zod v4 is installed

```
npm install zod
```

### Optional Packages

[](#optional-packages)

For additional features, install these optional packages:

```
# For Spatie Data class support
composer require spatie/laravel-data

# For TypeScript transformer integration
composer require spatie/laravel-typescript-transformer
```

Configuration
-------------

[](#configuration)

To publish the configuration file, run:

```
php artisan vendor:publish --provider="RomegaSoftware\LaravelSchemaGenerator\LaravelSchemaGeneratorServiceProvider"
```

This will create a `config/laravel-schema-generator.php` file where you can customize output paths, formats, and integration settings.

### Generating Separate Files

[](#generating-separate-files)

By default, all schemas are generated into a single TypeScript file. You can configure the package to generate separate files for each schema (e.g., `UserSchema.ts`, `PostSchema.ts`) by enabling `separate_files` in the configuration.

```
// config/laravel-schema-generator.php

'zod' => [
    'output' => [
        'path' => resource_path('js/types/schemas.ts'), // fallback/default path
        'separate_files' => true,
        // Optional: specify a dedicated directory for separate files
        'directory' => resource_path('js/types/schemas'),
    ],
],
```

When enabled, the generator will:

1. Create individual `.ts` files for each schema.
2. Automatically resolve and inject imports for dependent schemas (e.g., if `UserSchema` references `AddressSchema`).

Quick Start
-----------

[](#quick-start)

1. **Add the attribute** to your Laravel validation classes:

```
use RomegaSoftware\LaravelSchemaGenerator\Attributes\ValidationSchema;

#[ValidationSchema]
class CreateUserRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:255',
            'email' => 'required|email',
            'age' => 'nullable|integer|min:18',
        ];
    }
}
```

2. **Generate the schemas**:

```
php artisan schema:generate
```

3. **Use in TypeScript**:

```
import { CreateUserRequestSchema } from "@/types/schemas";

const result = CreateUserRequestSchema.safeParse(formData);
if (result.success) {
  // Data is valid
  await api.createUser(result.data);
}
```

Documentation
-------------

[](#documentation)

For complete documentation, configuration options, advanced features, and examples, visit:

**📚 [Official Documentation](https://laravel-schema-generator.romegasoftware.com)** Coming Soon

Custom Schema Overrides
-----------------------

[](#custom-schema-overrides)

When you need to keep bespoke Laravel validation logic but still describe the TypeScript shape, provide a literal override using the fluent helper. Prefix the snippet with `.` when you want to append behaviour to the inferred Zod builder instead of replacing it entirely:

```
use RomegaSoftware\LaravelSchemaGenerator\Support\SchemaRule;

'items' => [
    'required',
    'array',
    SchemaRule::make(
        static function ($attribute, $value, $fail, string $message): void {
            if (collect($value)->sum('qty') < 12) {
                $fail($message);
            }
        }
    )
        ->append(static function (string $encodedMessage): string {
            return failWith('You must order at least 12 total units.'),
],
```

Because the override begins with `.`, the generator keeps the inferred base (`z.array(...)`) and simply appends your refinement. The callable passed to `append()` receives the JSON-encoded message as its first argument (and the raw message as a second argument if you declare it). When you want to replace the builder outright, omit the leading dot and provide the complete Zod expression (for example `z.array(z.object({ ... }))`).

Prefer dedicated rule objects? Implement `SchemaAnnotatedRule` and reuse the same fluent API with the provided trait:

```
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use RomegaSoftware\LaravelSchemaGenerator\Concerns\InteractsWithSchemaFragment;
use RomegaSoftware\LaravelSchemaGenerator\Contracts\SchemaAnnotatedRule;

final class TotalOrderItemsRule implements SchemaAnnotatedRule, ValidationRule
{
    use InteractsWithSchemaFragment;

    public function __construct()
    {
        $this->withFailureMessage('You must order at least 12 total cases.')
            ->append(function (?string $encodedMessage) {
                return sum('quantity') < 12) {
            $fail($this->failureMessage() ?? 'You must order at least 12 total units.');
        }
    }
}
```

Both approaches surface the schema fragment directly alongside the validation logic and are picked up automatically by the generator for FormRequests and Spatie Data classes.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for development setup and contribution guidelines.

License
-------

[](#license)

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

Credits
-------

[](#credits)

- [Romega Software](https://romegasoftware.com/)
- [All Contributors](../../contributors)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance88

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.1% 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 ~13 days

Recently: every ~30 days

Total

15

Last Release

58d ago

Major Versions

v0.4.0 → v1.0.02025-10-19

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/219298?v=4)[Braden Keith](/maintainers/bradenkeith)[@bradenkeith](https://github.com/bradenkeith)

---

Top Contributors

[![bradenkeith](https://avatars.githubusercontent.com/u/219298?v=4)](https://github.com/bradenkeith "bradenkeith (73 commits)")[![A909M](https://avatars.githubusercontent.com/u/119125167?v=4)](https://github.com/A909M "A909M (2 commits)")[![VolkerLieber](https://avatars.githubusercontent.com/u/42102008?v=4)](https://github.com/VolkerLieber "VolkerLieber (1 commits)")

---

Tags

laravellaravel-packagephpspatie-laravelspatie-laravel-datazodzod-validationzod-validatorslaravelschemavalidationgeneratortypescriptzod

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/romegasoftware-laravel-schema-generator/health.svg)

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

###  Alternatives

[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[proengsoft/laravel-jsvalidation

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

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

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

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)[galahad/laravel-addressing

Laravel package providing addressing functionality

70316.6k](/packages/galahad-laravel-addressing)

PHPackages © 2026

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