PHPackages                             robtesch/inertia-form-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. robtesch/inertia-form-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

robtesch/inertia-form-generator
===============================

A package to transform your Laravel FormRequests into type-safe Inertia forms

v2.1.0(2mo ago)01.0k↓41.1%[4 PRs](https://github.com/robtesch/inertia-form-generator/pulls)MITPHPPHP ^8.4CI passing

Since Sep 5Pushed 1mo agoCompare

[ Source](https://github.com/robtesch/inertia-form-generator)[ Packagist](https://packagist.org/packages/robtesch/inertia-form-generator)[ Docs](https://github.com/robtesch/inertia-form-generator)[ GitHub Sponsors](https://github.com/robtesch)[ RSS](/packages/robtesch-inertia-form-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (14)Versions (8)Used By (0)

Inertia Form Generator
======================

[](#inertia-form-generator)

A small Laravel package that transforms your Laravel FormRequest validation rules into type-safe TypeScript definitions and ready-to-use Inertia useForm initializers.

The package parses FormRequest classes in app/Http/Requests, maps validation rules to TypeScript types (with support for class-based validation rules, enums and custom mappings), and exports a single TypeScript file with exported types and useForm instances for your front-end.

### Features

[](#features)

- Generates TypeScript type definitions from Laravel FormRequest rules.
- Generates Inertia useForm initializers for Vue, React or Svelte.
- Supports PHP 8.x enums used with the Enum validation rule.
- Allows custom type mappings via configuration.
- Command-line generator: php artisan inertia-form-generator:generate

### Requirements

[](#requirements)

- PHP: ^8.4 (as declared in composer.json)
- Laravel 9/10/11 compatible components (package depends on illuminate/\* components via composer)

### Installation

[](#installation)

1. Install with Composer:

```
composer require robtesch/inertia-form-generator --dev
```

2. Publish the configuration file (so you can change output path, front-end provider, custom mappings, etc.):

You can publish the config using either the provider or the package tag:

```
# By provider
php artisan vendor:publish --provider="RobTesch\InertiaFormGenerator\InertiaFormGeneratorServiceProvider" --tag="config"

# Or by tag (some projects may prefer this tag name)
php artisan vendor:publish --tag="inertia-form-generator-config"
```

### Configuration

[](#configuration)

The published config file config/inertia-form-generator.php contains the key options:

- output-file-path: string — Path where the generated TypeScript file will be written. Default: resources/js/formRequests.ts
- front-end-provider: string — One of: 'vue', 'react', 'svelte4', 'svelte5' (controls which useForm import is used). Default: 'vue'
- user-model: string|null — Fully qualified user model used to create a fake user when FormRequests rely on an authenticated user. Default: 'App\\Models\\User'
- custom\_mappings: array — Map validation rule class names or string rule names to custom TypeScript type strings. Example: \['App\\Rules\\YourCustomRule' =&gt; 'string | null'\]

See config/inertia-form-generator.php for the exact defaults shipped with the package.

### Usage

[](#usage)

1. Create or ensure you have FormRequest classes under app/Http/Requests with rules() defined as usual.
2. Run the generator command to produce the TypeScript file:

```
php artisan inertia-form-generator:generate
```

By default the command writes to the path configured in config/inertia-form-generator.php (resources/js/formRequests.ts by default) and prints the resulting path.

#### What gets generated

[](#what-gets-generated)

For each FormRequest found, the package will export a TypeScript type and a useForm initializer. Example output (illustrative):

```
import { useForm } from '@inertiajs/vue3';

export const exampleRequestForm = useForm({
  name: '' as string,
  age: null as number | null,
} satisfies ExampleRequest);
```

Once you have generated your TypeScript file, you can simply import the form you need in your front-end code.

```
// ExampleComponent.vue

import { exampleRequestForm } from '@/js/formRequests';
import { usePage } from '@inertiajs/vue3';

const page = usePage();
//Optionally set default values
exampleRequestForm.defaults({
  name: page.props.auth.user.name,
  age: page.props.auth.user.age,
});

    Submit

```

You will benefit from type-safety and all of Inertia's amazing useForm features.

### Notes and behavior

[](#notes-and-behavior)

- The generator maps common validation rules (string, integer, numeric, boolean, array, file, etc.) to TypeScript types. Complex or custom rule objects can be mapped by adding entries to custom\_mappings in the config.
- Enum validation rules are supported; the generator will attempt to map PHP enums to a TypeScript string literal union and will set an initial value using the first enum case when possible.
- If a FormRequest needs an authenticated user, set the user-model config to a model that has a factory so the generator can instantiate a fake user during parsing. If you don't need this behavior, set user-model to null.
- The package uses auto-discovery (service provider is registered via composer extra) and registers a single Artisan command: inertia-form-generator:generate.

### Extending and Custom Mappings

[](#extending-and-custom-mappings)

Add mappings for custom rule classes or rule names in config/inertia-form-generator.php under the custom\_mappings key. The key should be the validation rule string or the full class name of the rule, and the value should be the TypeScript type string you want to emit.

```
'custom_mappings' => [
    App\Rules\GeoPoint::class => 'CustomPointInterface | null',
    'binary' => 'Blob',
],
```

### Excluding FormRequests

[](#excluding-formrequests)

You can exclude FormRequests from being parsed by adding them to the exclude array in the config. This can be useful in cases where the validation is particularly complex and this generator is not able to parse it correctly.

```
'exclude' => [
    \App\Http\Requests\ExampleRequest::class,
],
```

### Testing

[](#testing)

Run the package tests with:

```
composer test
```

### Development notes

[](#development-notes)

- Primary PHP entrypoint: src/InertiaFormGenerator.php
- Artisan command implementation: src/Commands/InertiaFormGeneratorCommand.php
- Package service provider: src/InertiaFormGeneratorServiceProvider.php
- Default config: config/inertia-form-generator.php

### License

[](#license)

This package is open-source under the MIT License — see LICENSE.md for details.

### Contributing

[](#contributing)

This package has primarily been developed and tested with my specific use case in mind. Fixes and improvements are welcome. Please open issues or pull requests on the project repository and follow the coding standards and test suites included in the package.

### Credits

[](#credits)

- Author: Robert Teschmacher

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance87

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~57 days

Total

4

Last Release

84d ago

Major Versions

v1.0.1 → v2.0.02025-09-08

### Community

Maintainers

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

---

Top Contributors

[![robtesch](https://avatars.githubusercontent.com/u/30407321?v=4)](https://github.com/robtesch "robtesch (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelrobteschinertia-form-generator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/robtesch-inertia-form-generator/health.svg)

```
[![Health](https://phpackages.com/badges/robtesch-inertia-form-generator/health.svg)](https://phpackages.com/packages/robtesch-inertia-form-generator)
```

###  Alternatives

[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)

PHPackages © 2026

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