Search by

rylacdang / formcast

rylacdang

Cast your Laravel FormRequest rules to typed Zod schemas, TypeScript types, and Laravel-identical error messages.

Package info

github.com/rylacdang/formcast

pkg:composer/rylacdang/formcast

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v0.1.0 2026-11-24 16:03 UTC

This package is auto-updated.

Last update: 2026-11-24 16:19:26 UTC


README

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.