roundly-consulting / forms-for-laravel
Manage form structures, fields, and submissions in the database.
Package info
github.com/roundly-consulting/forms-for-laravel
pkg:composer/roundly-consulting/forms-for-laravel
Fund package maintenance!
Requires
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.8|^9.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Forms for Laravel
Define multi-step forms — groups and fields — in your database, validate user input against per-field rules, and store submissions you can read back as typed answers. Everything is driven by Eloquent models you can swap for your own.
Installation
Requires PHP 8.4, Laravel 12 or 13.
composer require roundly-consulting/forms-for-laravel php artisan vendor:publish --tag="forms-migrations" php artisan vendor:publish --tag="approvals-migrations" --tag="attributes-migrations" --tag="media-migrations" php artisan migrate
The migrations are not loaded automatically, and the companion packages' migrations are needed
too. If your senders have UUID/ULID keys, set FORMS_KEY_TYPE before migrating.
Usage
Define a form once, with its groups (steps) and fields:
use RoundlyConsulting\Forms\Facades\Forms; use RoundlyConsulting\Forms\GroupBuilder; Forms::define('contact', 'Contact us') ->public() ->group('details', 'Your details', function (GroupBuilder $g): void { $g->field('name', 'Name')->rules(['required', 'string']); $g->field('email', 'Email')->email()->required(); }) ->group('message', 'Message', function (GroupBuilder $g): void { $g->field('body', 'Message')->textarea()->required(); }) ->create();
Validate and store a submission — input arrives keyed by form.group.field
(contact.details.name):
$form = Forms::find('contact'); Forms::validate(form: $form, request: $request); // throws ValidationException on failure $result = Forms::submit(form: $form, request: $request, sender: $request->user()); $result->uuid; // the submission's reference id
Read the answers back, one keyed set per submission:
$answers = Forms::submissions($form)->latest()->get(); $answers->first()->values; // ['name' => 'Jane', 'email' => 'jane@example.com', 'body' => 'Hello!']
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/forms-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see LICENSE for more information.