laravel-enso/formbuilder
最新稳定版本:9.1.1
Composer 安装命令:
composer require laravel-enso/formbuilder
包简介
JSON-based form builder for Laravel Enso
README 文档
README
Description
Forms is the JSON-based form builder used across Laravel Enso backends.
The package loads form templates from JSON, builds create and edit payloads around Eloquent models, computes actions and meta configuration, validates template structure, and ships test traits for common create/edit/destroy flows.
It is a backend payload builder, not a standalone UI package. The canonical frontend companion is @enso-ui/forms, which renders the payloads produced by this package.
Installation
Install the package:
composer require laravel-enso/forms
Optional publishes:
php artisan vendor:publish --tag=forms-config php artisan vendor:publish --tag=forms-resources
Features
- JSON template loading through
Form. - Create and edit payload generation for Eloquent-backed forms.
- Runtime mutation helpers for values, labels, options, visibility, readonly state, and route metadata.
- Template validation for structure, actions, routes, and fields.
- PHPUnit test traits for form workflows.
- Direct integration with the Enso frontend form renderer and its field components.
Usage
Create or edit a form payload:
use LaravelEnso\Forms\Services\Form; $form = new Form(__DIR__.'/Templates/example.json'); $createPayload = $form->create(); $editPayload = $form->edit($model);
Template structure
The JSON template must include at least:
methodsectionsrouteParams
The root template may also include:
title,iconactionsauthorizeautosaveclearErrorsControldebouncedividerTitlePlacementlabelsparamsreadonlyroutePrefixroutestabs
Each section must define:
columnsfields
Optional section attributes are:
dividertitlecolumntabslothidden
Each field must define:
labelnamevaluemeta
Minimal template example
{
"title": "Example",
"icon": "user",
"method": null,
"routePrefix": "administration.users",
"routeParams": {},
"actions": ["store", "update", "destroy", "back"],
"sections": [
{
"columns": 2,
"title": "General",
"fields": [
{
"label": "Name",
"name": "name",
"value": "",
"meta": {
"type": "input",
"content": "text",
"custom": false
}
},
{
"label": "Roles",
"name": "roles",
"value": [],
"meta": {
"type": "select",
"multiple": true,
"source": "administration.roles.options",
"custom": false
}
}
]
}
]
}
Form service API
The LaravelEnso\Forms\Services\Form object is not just a loader. It is a fluent mutator for the template before create() or edit() finalizes the payload.
Common methods:
create(?Model $model = null)edit(Model $model)actions(...$actions)routePrefix(string $prefix)route(string $action, string $route)routeParams(array $params)title(string $title)icon(string $icon)append(string $param, mixed $value)authorize(bool $authorize)labels(bool $labels)
Field and section mutators:
label(string $field, string $value)options(string $field, mixed $value)value(string $field, mixed $value)meta(string $field, string $param, mixed $value)columns(string $section, int $value)hide(...$fields)/show(...$fields)disable(...$fields)readonly(...$fields)readonly()/readonly(bool $readonly)hideSection(...$sections)/showSection(...$sections)hideTab(...$tabs)/showTab(...$tabs)
Example:
use LaravelEnso\Forms\Services\Form; $form = (new Form(app_path('Forms/Templates/users.json'))) ->title('Edit User') ->icon('user') ->routePrefix('administration.users') ->append('locale', app()->getLocale()) ->label('email', 'Login Email') ->options('role_id', $roles) ->value('is_active', true) ->readonly('email') ->readonly() ->hide('password') ->meta('phone', 'placeholder', '+40 700 000 000'); $payload = $form->edit($user);
Supported field types
The backend validator accepts these meta.type values:
inputselectdatepickertimepickertextareapasswordwysiwyg
The frontend companion @enso-ui/forms currently renders these combinations:
inputwithcontent: textinputwithcontent: numberinputwithcontent: emailinputwithcontent: passwordinputwithcontent: encryptinputwithcontent: moneyinputwithcontent: checkboxselecttextareadatepickertimepickerwysiwyg
Important behavior:
- encrypted inputs are returned as
************************when the model already has a value - root
readonlyis preserved in the payload so the frontend can render the whole form without mutating actions - field-level
meta.readonlyremains available for locking individual fields - multi-select values are normalized to arrays of tracked keys
- datepicker values are formatted with the configured or field-specific format
- select
sourceroutes are converted to relative application paths - select fields that define enum class
optionsare expanded through::select()and default to translated labels wysiwygfields use TinyMCE by default and receive the configured TinyMCE API key automaticallywysiwygfields may seteditor: trixto use the Trix frontend editor instead
Supported meta keys
The validator accepts the following optional meta keys:
options,multiple,custom,contentstep,min,maxdisabled,readonly,hiddensource,format,altFormat,timerows,placeholdertrackBy,labeltooltip,symbol,precision,thousand,decimalpositive,negative,zeroresize,translatedtime12hr,disable-clearobjects,toolbar,plugins,editor,taggablesearchMode,params,pivotParams,customParams
Template validation rules
Validator runs four checks:
Structure: verifies root attributes, section format, columns, and tab consistencyActions: only allows Enso form actions supported by the packageRoutes: requires actual named routes for every action exceptbackFields: verifies field attributes, checkbox values, select value shape, and delegatesmetavalidation
Notable enforced rules:
- create forms can use only
backandstore - update forms can use only
back,create,show,update, anddestroy selectfields must defineoptionsorsource- checkbox fields must have boolean values
- multi-select fields must receive array or object values
columns: customrequires an integercolumnper field
Enum-backed select fields may opt out of frontend label translation by setting
"translated": false explicitly in the template.
Frontend companion
The canonical renderer is @enso-ui/forms.
Its public Vue components are:
EnsoFormVueFormCoreForm
The package integrates with companion UI packages such as:
@enso-ui/select@enso-ui/datepicker@enso-ui/wysiwyg@enso-ui/money@enso-ui/switch@enso-ui/tabs
EnsoForm also exposes runtime helpers to the host application, including:
fetch()submit()field(name)param(name)routeParam(name)fill(state)setOriginal()undo()hideField(name)/showField(name)hideTab(name)/showTab(name)
API
Services
LaravelEnso\\Forms\\Services\\FormLaravelEnso\\Forms\\Services\\BuilderLaravelEnso\\Forms\\Services\\Validator
Published resources
config/enso/forms.phpapp/Forms/Builders/ModelForm.phpapp/Forms/Templates/template.php
Configuration highlights
validationsbuttonsaltDateFormatselectPlaceholderauthorizedividerTitlePlacementlabelstinyMCEApiKey
Test traits
CreateFormEditFormDestroyForm
Depends On
Required Enso packages:
Companion frontend package:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!
laravel-enso/formbuilder 适用场景与选型建议
laravel-enso/formbuilder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.65k 次下载、GitHub Stars 达 123, 最近一次更新时间为 2017 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Forms」 「form-builder」 「laravel-enso」 「json-templates」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravel-enso/formbuilder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-enso/formbuilder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravel-enso/formbuilder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enums for Laravel Enso
Company management dependency for Laravel Enso
Person management for Laravel Enso
Image transformer dependency for Laravel Enso
The laravel-form-builder's bootstrap 4 template.
Search and interval helpers for Laravel Enso
统计信息
- 总下载量: 18.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 123
- 点击次数: 15
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-08