New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

rylacdang/formcast

Cast your Laravel FormRequest rules to typed Zod schemas, TypeScript types, and Laravel-identical error messages.
9 1
Install
composer require rylacdang/formcast
Latest Version:v0.1.1
PHP:^8.3
Laravel:12 · 13
License:MIT
Last Updated:Nov 24, 2026
Links: GitHub  ·  Packagist
Maintainer: rylacdang

Formcast

Cast your Laravel FormRequest rules to the client.

PHP Tests JS Tests Parity Static Analysis License: MIT

Formcast reads your Laravel FormRequest classes and generates typed Zod schemas, TypeScript types, and Laravel-identical error messages for your Inertia (Vue / React) and standalone (Expo / Axios) apps. Client-safe rules validate instantly in the browser (0 ms), while server-only rules (unique, exists, closures) are routed through Inertia's built-in Precognition only after client checks pass.

[!CAUTION] Client-side validation is for user experience only. Laravel validation on the server is never optional.

Installation

composer require rylacdang/formcast
npm install -D @rylacdang/formcast zod
php artisan formcast:install

Add the Vite plugin to vite.config.ts:

import { formcast } from '@rylacdang/formcast/vite';

export default defineConfig({
  plugins: [
    laravel({ input: ['resources/js/app.ts'], refresh: true }),
    vue(), // or react()
    wayfinder({ formVariants: true }),
    formcast(),
  ],
});

60-Second Example

1. Write your normal Laravel FormRequest

class StoreOrderRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'customer_email'     => ['required', 'email', 'max:255', 'unique:orders,customer_email'],
            'payment_method'     => ['required', Rule::enum(PaymentMethod::class)],
            'gcash_reference'    => ['nullable', 'required_if:payment_method,gcash', 'string', 'size:13'],
            'items'              => ['required', 'array', 'min:1'],
            'items.*.product_id' => ['required', 'integer', 'exists:products,id'],
            'items.*.quantity'   => ['required', 'integer', 'min:1', 'max:99'],
            'notes'              => ['nullable', 'string', 'max:500'],
        ];
    }

    public function attributes(): array
    {
        return ['gcash_reference' => 'GCash reference number'];
    }
}

2. Generate typed casts (or let the Vite plugin do it automatically)

php artisan formcast:generate

3. Use in Vue or React with Inertia + Wayfinder

<script setup lang="ts">
import { useFormcast } from '@rylacdang/formcast/vue';
import StoreOrderRequest from '@/formcast/App/Http/Requests/StoreOrderRequest';
import { store } from '@/actions/App/Http/Controllers/OrderController';

const form = useFormcast(StoreOrderRequest, {
  customer_email: '',
  payment_method: 'cash',
  gcash_reference: null,
  items: [{ product_id: 1, quantity: 1 }],
  notes: null,
});
</script>

<template>
  <form @submit.prevent="form.submit(store())">
    <input v-model="form.customer_email" @blur="form.touch('customer_email')" />
    <p v-if="form.invalid('customer_email')">{{ form.errors.customer_email }}</p>
    <span v-if="form.validating">Checking…</span>
    <button :disabled="form.processing || form.hasErrors">Place order</button>
  </form>
</template>

Why Formcast?

Feature Other Zod generators Precognition only Formcast
FormRequest → Zod + TS types ✅ ❌ ✅
Laravel-identical messages (messages(), attributes(), lang/) ❌ / partial ✅ ✅
Hybrid validation (Zod first, Precognition only for server rules) ❌ ❌ (every check hits server) ✅
First-class Inertia useFormcast() (Vue & React) ❌ ✅ ✅
Vite plugin with debounced auto-regeneration ❌ N/A ✅
Controller/route mapping (usedBy, Wayfinder-ready) ❌ N/A ✅
Laravel semantics (TrimStrings, "" = missing, "5" int) partial ✅ ✅
Automated Laravel-vs-Zod parity suite ❌ N/A ✅
Framework-agnostic core (Expo / React Native / Axios) ❌ ❌ ✅
Ships Laravel Boost guidelines & AI skill ❌ ❌ ✅

Documentation

License

Formcast is open-sourced software licensed under the MIT license.

Related Packages

dragosstoenica/laravel-zod

Generate Zod v4 TypeScript schemas from Spatie Laravel Data classes (output) and...

1,717 1
arnaldo-tomo/laravel-autoscema

Automatically generate TypeScript types and validation schemas from Laravel Mode...

1,281 21
romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

42,837 34
codenyra/precognition-plus

Checks common Laravel FormRequest rules in the browser for Precognition forms, w...

4 0
anik/form-request

Form request is a package for Lumen that lets developer validate form requests l...

403,142 50

Version History

Version Released PHP Laravel License
v0.1.1 ^8.3 ^12.0 || ^13.0 MIT
v0.1.0 ^8.3 ^12.0 || ^13.0 MIT