AgentSkillsCN

livewire-form-object

构建表单对象,集中管理表单数据、验证逻辑与状态。将字段定义、验证规则、错误处理以及数据持久化等功能,与UI组件分离管理。在创建结构化表单数据容器、实现验证逻辑,或管理表单状态与提交时自动激活。

SKILL.md
--- frontmatter
name: livewire-form-object
description: >-
    Build Form Objects that centralize form data, validation, and state management.
    Handles field definitions, validation rules, error handling, and data
    persistence separate from UI components. Activates when creating structured form
    data containers, implementing validation logic, or managing form state and
    submission.

When to use me

  • When form logic needs to be reused across multiple components
  • When forms are large and need better organization
  • When the same form is used in different contexts (create vs edit)

Initial Setup

bash
php artisan livewire:form ModelFormObject
php
namespace App\Livewire\Forms;

use App\Models\Model;
use Livewire\Attributes\Validate;
use Livewire\Form;
use Naykel\Gotime\Traits\Crudable;
use Naykel\Gotime\Traits\Formable;

class ModelFormObject extends Form
{
    use Crudable, Formable;

    public function init(Model $model): void
    {
        $this->editing = $model;
        $this->setFormProperties($this->editing);
    }
}