mrgiant/form-builder
Composer 安装命令:
composer require mrgiant/form-builder
包简介
A Laravel form-builder module: dynamic forms, questions, responses, approval workflows, with Vue 3 builder components and Blade renderers.
README 文档
README
A Laravel form-builder module extracted from the GoldenHospital application: dynamic forms, questions/fields, responses, and an approval-workflow engine, with Vue 3 builder components and Blade renderers (including PDF templates).
- Backend:
Form,Question,Answer,FormResponse, plus the workflow models (FormResponseWorkflow,FormResponseWorkflowAction,FormWorkflowNode,FormWorkflowEdge), 5 controllers, and all migrations. - Frontend: a drag-and-drop question builder, a visual workflow builder, 12 field-type renderers, responses list, and an approvals inbox/tracker.
- Views: public form render (
custom_render), pre-filled render, and PDF templates.
Requirements
- PHP
^8.2 - Laravel
^12or^13
Host-provided dependencies
This package was extracted from a monolith and is designed to be consumed by
that same application. The controllers and the Translatable concern therefore
still reference a handful of classes that the host app must provide. These
are intentionally left pointing at the App\ namespace:
| Referenced class | Used by | Purpose |
|---|---|---|
App\Http\Controllers\Controller |
all controllers | base controller (auth/validation traits) |
App\Models\User |
WorkflowController, FormResponseWorkflowAction, Services\WorkflowRunner |
approver identity |
App\Notifications\GeneralNotficationMailsAttachment |
AnswerController |
submit-notification email (host-env: shells out to a node PDF script + hardcoded domain) |
App\Http\Services\ReportsGenerator\PdfFooter |
ResponsesController |
PDF footer |
App\Http\TranslatorAction\Translator, App\Models\Translation |
Concerns\Translatable |
i18n fields |
The workflow engine and its collaborators now live in the package —
Mrgiant\FormBuilder\Services\WorkflowRunner,
Mrgiant\FormBuilder\Notifications\FormWorkflowNotification, and
Mrgiant\FormBuilder\Rules\UniqueAnswerResponses — since they are form-domain
logic, not host infrastructure. The remaining App\ references above are
genuine host concerns (identity, generic mail/PDF/Excel tooling, i18n).
Installation (local path repository)
In the host app's composer.json:
"repositories": [ { "type": "path", "url": "../form-builder", "options": { "symlink": true } } ],
then:
composer require mrgiant/form-builder:*
The service provider is auto-discovered. It will:
- load the package migrations (deduped by filename against the host's copies),
- register the
form-builder::view namespace, - register routes only if
config('form-builder.register_routes')is true (off by default to avoid colliding with the host's existing form routes).
Publish what you want to customize:
php artisan vendor:publish --tag=form-builder-config # config/form-builder.php php artisan vendor:publish --tag=form-builder-views # resources/views/vendor/form-builder php artisan vendor:publish --tag=form-builder-assets # resources/js/vendor/form-builder php artisan vendor:publish --tag=form-builder-migrations # only for a fresh host
Frontend
The package ships raw .vue source. Publish it and register the components
on your existing global Vue app:
// resources/js/app.js (host) import { registerFormBuilder } from './vendor/form-builder'; registerFormBuilder(app, { lazy }); // reuse the host's lazy() wrapper
This registers: forms-index, forms-manage-questions,
forms-questions-answers, forms-responses-index, forms-workflow-builder,
approvals-inbox, approval-tracker, form-charts.
The components require golden-logic-ui, vuedraggable, and Vue 3 in the host.
They also import a few host-provided Vue libraries via the @ alias
(@ → resources/js), which the host must define in vite.config.js:
| Import | Provided by host at |
|---|---|
@/services/multilingualService |
resources/js/services/ |
@/components/fields/* |
shared field inputs (also used by other host features) |
@/components/fieldsAnswer/* |
shared answer-display inputs |
@/components/Charts/Pie.vue |
shared chart components |
These are intentionally not bundled so the host owns a single copy (they are
shared with other host features). Re-run the publish command after updating the
package to refresh the copy under resources/js/vendor/form-builder.
Configuration
config/form-builder.php:
| Key | Default | Meaning |
|---|---|---|
register_routes |
false |
Let the package own the form routes. |
route_prefix |
admin |
URL prefix for the route group. |
route_name_prefix |
admin. |
Route-name prefix (admin.forms.*). |
middleware |
['web', 'auth'] |
Middleware for the route group. |
user_model |
App\Models\User |
Approver model. |
Cutover status (GoldenHospital host)
The cutover has been performed in the GoldenHospital host — the package is the source of truth for the module's models, controllers, and Vue components:
- ✅ Host
app/Models/{Form,Question,Answer,FormResponse,FormResponse*,FormWorkflow*}.phpdeleted; all references repointed toMrgiant\FormBuilder\Models\*. - ✅ Host
app/Http/Controllers/Admin/{Forms,Questions,Answer,Responses,Workflow}Controller.phpdeleted;routes/web.php+routes/api.phpnow reference the package controllers. (The route definitions stay in the host so they keep the host's admin middleware/locale/gate context;register_routesremainsfalse.) - ✅ Host
resources/js/components/cruds/Forms/**andFormCharts.vuedeleted;app.jsregisters the components viaregisterFormBuilder(app, { lazy })from the publishedresources/js/vendor/form-builder.
Remaining (optional) hardening:
- Blade views still live in the host (the controllers render
admin.forms.*/forms.*, which resolve to the host's layouts). The package ships its own copies underform-builder::for external consumers. - Decouple the host-provided PHP classes and Vue libraries (tables above) for a fully standalone package.
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-04