joshcirre / inertiakit
File-based Inertia routing, simplified server controllers + typed models & props
Requires
- php: ^8.1.0
- inertiajs/inertia-laravel: ^2.0
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.18.1
- pestphp/pest: ^3.5.1
- pestphp/pest-plugin-type-coverage: ^3.1
- phpstan/phpstan: ^1.12.7
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
This package is auto-updated.
Last update: 2025-04-25 22:50:07 UTC
README
inertiaKIT (WIP)
inertiaKIT is a zero-boilerplate approach to file-based routing and typed props in Laravel + InertiaJS created by Josh Cirre. It auto-generates:
- Routes (and optional Controllers) from
resources/js/pages/*.server.php
- TypeScript interfaces for your Eloquent models
- TypeScript interfaces for your page props, with camelCased keys and model types
⚠️ Alpha software—expect rough edges!
📦 Installation
-
Require the package
composer require joshcirre/inertia-kit:^0.0.10-alpha
-
Install the package
php artisan inertiakit:install
-
(Optional but recommended) Install Laravel Wayfinder for zero-config route-action types:
composer require laravel/wayfinder
⚙️ Configuration
Edit your config/inertiakit.php
to tailor:
return [ // Explicit Eloquent models to type, or empty = auto-discover all under app/Models 'models' => [], // Where to write your generated TS model interfaces 'types_output' => 'resources/js/types/models.d.ts', // Generate real Controllers under app/Http/Controllers/Generated 'use_controllers'=> env('INERTIAKIT_USE_CONTROLLERS', true), // Where to dump your auto-generated routes file 'routes_file' => 'routes/inertiakit.php', // Glob patterns under resources/js/pages to ignore 'ignore' => [ 'auth/*', 'settings/*', 'welcome', 'dashboard', ], ];
🚀 Usage
Run the generation command manually once php artisan inertiakit:generate
, or run the following as needed:
php artisan inertiakit:generate php artisan inertiakit:model-types php artisan inertiakit:page-types
🔄 Automatic Re-generation with Vite
For seamless DX, you can hook up a file watcher in your vite.config.js
. (this is done automatically when you run inertiakit:install
)
npm install -D vite-plugin-run
And in your vite.config.js
:
import laravel from 'laravel-vite-plugin'; import { run } from 'vite-plugin-run'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ laravel({ input: ['resources/css/app.css', 'resources/js/app.tsx'], ssr: 'resources/js/ssr.tsx', refresh: true, }), run([ { name: 'inertiakit:types', run: ['php', 'artisan', 'inertiakit:model-types && php artisan inertiakit:page-types'], pattern: ['app/Models/**/*.php', 'resources/js/pages/**/*.server.php'], }, ]), ], });
📖 Further Reading
Happy coding! 🎉