承接 ivanmercedes/laravel-forminertia 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ivanmercedes/laravel-forminertia

Composer 安装命令:

composer require ivanmercedes/laravel-forminertia

包简介

A plug-and-play form builder for Laravel’s Inertia Starter Kit — powered by ShadCN UI.

README 文档

README

A plug-and-play form builder for Laravel’s Inertia Starter Kit — powered by ShadCN UI.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require ivanmercedes/laravel-forminertia

Then run the installation command to publish the default resources:

php artisan forminertia:install

Auto-Generate Forms from Database Tables

FormInertia can automatically generate form classes based on your database table structure, similar to Filament's generate command:

# Generate form from model/table
php artisan forminertia:generate User

# Generate with custom table name
php artisan forminertia:generate User --table=custom_users

# Exclude specific columns
php artisan forminertia:generate User --exclude=password,remember_token

# Force overwrite existing form
php artisan forminertia:generate User --force

# Custom output path
php artisan forminertia:generate User --path=app/Forms/Custom/UserForm.php

The command will:

  • Analyze your table structure
  • Map column types to appropriate form fields
  • Generate validation rules based on nullable columns
  • Exclude common system columns (id, timestamps, etc.)
  • Create a ready-to-use form class

Example generated form:

<?php

namespace App\Forms;

use LaravelForminertia\Base\Form;
use LaravelForminertia\Fields\TextField;
use LaravelForminertia\Fields\TextareaField;
use LaravelForminertia\Fields\CheckboxField;

class UserForm extends Form
{
    public function schema(): array
    {
        return [
            TextField::make('name')
                ->label('Name')
                ->placeholder('Enter name')
                ->required(),

            TextField::make('email')
                ->label('Email')
                ->placeholder('Enter email')
                ->required(),

            TextareaField::make('bio')
                ->label('Bio')
                ->placeholder('Enter bio')
                ->rows(4),

            CheckboxField::make('is_active')
                ->label('Is Active')
                ->default(false),
        ];
    }
}

Component Compatibility

FormInertia uses the same ShadCN UI components that come with the Laravel + Inertia Starter Kit, including Input, Select, and Checkbox.

However, since the Starter Kit doesn’t include a Textarea component by default, FormInertia automatically installs it during setup to ensure full compatibility out of the box.

Usage Example

1. Define your schema

Each form is a PHP class that defines its structure (sections, grids, and fields).

<?php

namespace App\Forms;

use LaravelForminertia\Base\Form;
use LaravelForminertia\Base\Grid;
use LaravelForminertia\Base\Section;
use LaravelForminertia\Fields\{TextField, SelectField, CheckboxField, TextareaField};

class UserForm extends Form
{
    public function schema(): array
    {
        return [
            Section::make('User Information')
                ->schema([
                    Grid::make(2)
                        ->schema([
                            TextField::make('name')
                                ->label('Full Name')
                                ->placeholder('John Doe')
                                ->required(),
                            TextField::make('email')
                                ->label('Email Address')
                                ->type('email')
                                ->placeholder('user@example.com')
                                ->required(),
                            SelectField::make('role')
                                ->label('User Role')
                                ->required()
                                ->options([
                                    'admin' => 'Administrator',
                                    'editor' => 'Editor',
                                    'user' => 'User',
                                ]),
                        ])
                ]),
            Section::make('Preferences')
                ->schema([
                    CheckboxField::make('is_active')
                        ->label('Active Account'),
                    TextareaField::make('bio')
                        ->label('Biography')
                        ->rows(6)
                        ->placeholder('Tell us a bit about this user...'),
                ]),
        ];
    }
}

2. Create a Controller

The controller injects the schema into your Inertia view.

<?php

namespace App\Http\Controllers;

use App\Forms\UserForm;
use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;

class UserController extends Controller
{
    public function create()
    {
        // Create form without data (for new records)
        $form = UserForm::make();

        return Inertia::render('user/create', [
            'form' => $form,
        ]);
    }

    public function edit(User $user)
    {
        // Fill form with existing data - now works directly with models!
        $form = UserForm::make($user);

        return Inertia::render('user/edit', [
            'form' => $form,
        ]);
    }

    public function editWithDefaults()
    {
        // Fill form with custom default values
        $form = UserForm::make([
            'name' => 'John Doe',
            'email' => 'john@example.com',
            'role' => 'user',
            'is_active' => true,
        ]);

        return Inertia::render('user/create', [
            'form' => $form,
        ]);
    }
}

3. Then render it inside your page:

import { store } from "@/routes/users";
import FormBuilder, {
    FormBuilderProps,
} from "@/components/forminertia/form-builder";

export default function create({
    form,
}: {
    form: FormBuilderProps["formSchema"];
}) {
    return (
        <div className="max-w-3xl mx-auto">
            <FormBuilder
                formSchema={form}
                form={store.form()}
                submitLabel="Create User"
            />
        </div>
    );
}

Fill Data - Clean & Simple

Forminertia makes it incredibly easy to populate forms with existing data.Here are the different ways you can do it:

Method 1: Direct with Eloquent Models

// Fill form directly with Eloquent models
$user = User::find(1);
$form = UserForm::make($user);

Method 2: Direct Array Data

// Fill form with array data
$form = UserForm::make([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'role' => 'admin',
    'is_active' => true,
]);

Method 3: With Collections

// Works with Collections too
$userData = collect([
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
    'role' => 'editor',
]);
$form = UserForm::make($userData);

Method 4: Chain Fill Method

// Create form first, then fill
$form = UserForm::make()
    ->fill(['name' => 'Jane Doe', 'email' => 'jane@example.com'])
    ->build();

Method 5: Using fillFromModel Method

// Alternative method for any object with toArray()
$user = User::find(1);
$form = UserForm::make()->fillFromModel($user)->build();

Smart Data Handling: The form automatically detects the data type and converts it appropriately:

  • Eloquent Models: Automatically calls ->toArray()
  • Collections: Automatically calls ->toArray()
  • Arrays: Used directly
  • Objects with toArray(): Automatically converted
  • Other objects: Cast to array

Fields will automatically populate with matching data. Fields without matching data will use their default values or remain empty.

Features

  • Plug-and-play form builder for Laravel + Inertia (React)
  • Clean and simple data filling system
  • Define forms using PHP schemas (Sections, Grids, Fields)
  • Automatically renders dynamic forms in your Inertia React app
  • Type-safe integration between PHP and TypeScript
  • Includes an installer command (php artisan forminertia:install) to set up resources
  • Vue 3 + Inertia support coming soon

License

The MIT License (MIT). Please see License File for more information.

ivanmercedes/laravel-forminertia 适用场景与选型建议

ivanmercedes/laravel-forminertia 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Forms」 「laravel」 「inertia」 「form-builder」 「shadcn」 「forminertia」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ivanmercedes/laravel-forminertia 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ivanmercedes/laravel-forminertia 我们能提供哪些服务?
定制开发 / 二次开发

基于 ivanmercedes/laravel-forminertia 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-06