MakeInertiaForm Command Documentation / Dokumentasi Command MakeInertiaForm
English Documentation
Overview
TheMakeInertiaForm command is a custom Laravel Artisan command that generates Inertia form components from YAML configuration files. This command has been enhanced to utilize the form, view, and vue sections of YAML files to create comprehensive form components with TypeScript interface support.
Command Signature
Required Arguments
- yamlFile: Path to the YAML configuration file (relative to project root)
Available Options
--output-path=: Path where the generated Vue components will be saved (required)--route-prefix=: Sets the route prefix for form submission routes--model-variable=: Sets the variable name for the model object--entity-name=: Sets the entity name for the generated components--entity-name-lower=: Sets the lowercase entity name for routes
YAML Configuration Structure
The command now processes three sections of the YAML file:Section Details
Form Section:name: Field identifierlabel: Display label for the fieldmodel: Model property name for v-model bindingtype: Input type (text, textarea, email, password, number, etc.)validator: Laravel validation rulescreate: Whether to include in create formsedit: Whether to include in edit forms
name: Field identifierlabel: Display label for the fieldmodel: Model property nametype: Display type (text, textarea, date, boolean, image, etc.)visible: Whether to show in view components
name: TypeScript interface field nametype: Data type for TypeScript mappingnullable: Whether the field can be null/undefined
Enhanced Features
TypeScript Interface Generation
Thevue section now generates TypeScript interface fields:
Type Mapping
YAML types are mapped to TypeScript types:string,text,textarea,email→stringinteger,int,number→numberboolean,bool→booleandatetime,date,time,timestamp→stringjson,object→anyarray→any[]
Additional Field Generation
Fields defined in thevue section but not in the form section are generated as additional form fields that can be conditionally displayed.
Generated Components
The command generates three Vue components:- CreateForm.vue: Form for creating new entities
- EditForm.vue: Form for editing existing entities
- ShowView.vue: Read-only view component for displaying entity data
Placeholder Replacements
The generated components use the following placeholders:{{{pl_form_fields}}}: Generated form input fields{{{pl_form_models}}}: Generated form model definitions{{{pl_view_fields}}}: Generated view display fields{{{pl_vue_interface_fields}}}: TypeScript interface field definitions{{{pl_vue_additional_fields}}}: Additional fields from vue section{{pl_store_route}}: Route for creating entities{{pl_update_route}}: Route for updating entities{{pl_model_variable}}: Variable name for the model object
Usage Examples
Basic Usage
Real-World Example with Project YAML
Using the existing project YAML configuration:CreateForm.vue: Manager creation formEditForm.vue: Manager editing formShowView.vue: Manager display component
Field Type Support
Input Field Types
text: Standard text inputtextarea: Multi-line text inputemail: Email input with validationpassword: Password input (masked)number/integer: Numeric inputboolean/simpleswitch: Boolean toggle
View Component Types
text: Simple text displaytextarea: Multi-line text with whitespace preservationboolean: Badge display (Yes/No)date/datetime: Formatted date displayimage/imagecardview: Image display with fallback
Error Handling
The command includes comprehensive error handling:- Validates YAML file existence and format
- Validates required options (output-path)
- Creates output directories if they don’t exist
- Provides clear error messages for missing stub files
- Returns appropriate exit codes (0 for success, 1 for error)
Dependencies
This command requires:symfony/yamlpackage for YAML parsing- Laravel’s Console Command base class
- Properly formatted stub templates:
resources/views/stubs/inertia/js/CreateForm.vue.stubresources/views/stubs/inertia/js/EditForm.vue.stubresources/views/stubs/inertia/js/ShowView.vue.stub
Integration with Other Commands
This enhanced command now works seamlessly with:MakeInertiaColumns: Uses the samevuesection for TypeScript interface consistencyMakeInertiaCrud: Provides form components that integrate with generated CRUD interfaces
Best Practices
- Consistent Naming: Use consistent field names across
form,view, andvuesections - Type Safety: Define proper types in the
vuesection for better TypeScript support - Validation: Include proper validation rules in the
formsection - Visibility Control: Use the
visible,create, andeditflags to control field display - Nullable Fields: Mark optional fields as nullable in the
vuesection
Dokumentasi Bahasa Indonesia
Gambaran Umum
CommandMakeInertiaForm adalah perintah Laravel Artisan kustom yang menghasilkan komponen form Inertia dari file konfigurasi YAML. Command ini telah ditingkatkan untuk memanfaatkan seksi form, view, dan vue dari file YAML untuk membuat komponen form yang komprehensif dengan dukungan interface TypeScript.
Tanda Tangan Command
Argumen Wajib
- yamlFile: Path ke file konfigurasi YAML (relatif terhadap root proyek)
Opsi yang Tersedia
--output-path=: Path tempat komponen Vue yang dihasilkan akan disimpan (wajib)--route-prefix=: Mengatur prefix route untuk route pengiriman form--model-variable=: Mengatur nama variabel untuk objek model--entity-name=: Mengatur nama entitas untuk komponen yang dihasilkan--entity-name-lower=: Mengatur nama entitas huruf kecil untuk route
Struktur Konfigurasi YAML
Command ini sekarang memproses tiga seksi dari file YAML:Detail Seksi
Seksi Form:name: Identifier fieldlabel: Label tampilan untuk fieldmodel: Nama properti model untuk binding v-modeltype: Tipe input (text, textarea, email, password, number, dll.)validator: Aturan validasi Laravelcreate: Apakah disertakan dalam form createedit: Apakah disertakan dalam form edit
name: Identifier fieldlabel: Label tampilan untuk fieldmodel: Nama properti modeltype: Tipe tampilan (text, textarea, date, boolean, image, dll.)visible: Apakah ditampilkan dalam komponen view
name: Nama field interface TypeScripttype: Tipe data untuk mapping TypeScriptnullable: Apakah field bisa null/undefined
Fitur yang Ditingkatkan
Generasi Interface TypeScript
Seksivue sekarang menghasilkan field interface TypeScript:
Mapping Tipe
Tipe YAML dipetakan ke tipe TypeScript:string,text,textarea,email→stringinteger,int,number→numberboolean,bool→booleandatetime,date,time,timestamp→stringjson,object→anyarray→any[]
Komponen yang Dihasilkan
Command ini menghasilkan tiga komponen Vue:- CreateForm.vue: Form untuk membuat entitas baru
- EditForm.vue: Form untuk mengedit entitas yang ada
- ShowView.vue: Komponen view read-only untuk menampilkan data entitas
Contoh Penggunaan
Penggunaan Dasar
Penanganan Error
Command ini mencakup penanganan error yang komprehensif:- Memvalidasi keberadaan dan format file YAML
- Memvalidasi opsi yang diperlukan (output-path)
- Membuat direktori output jika belum ada
- Menyediakan pesan error yang jelas untuk file stub yang hilang
- Mengembalikan kode keluar yang sesuai (0 untuk sukses, 1 untuk error)
Dependencies
Command ini membutuhkan:- Package
symfony/yamluntuk parsing YAML - Kelas base Laravel Console Command
- Template stub yang terformat dengan benar
Best Practice
- Penamaan Konsisten: Gunakan nama field yang konsisten di seluruh seksi
form,view, danvue - Type Safety: Definisikan tipe yang tepat di seksi
vueuntuk dukungan TypeScript yang lebih baik - Validasi: Sertakan aturan validasi yang tepat di seksi
form - Kontrol Visibilitas: Gunakan flag
visible,create, danedituntuk mengontrol tampilan field - Field Nullable: Tandai field opsional sebagai nullable di seksi
vue
