### Install Forms for Laravel with Composer and Artisan Source: https://github.com/roundly-consulting/forms-for-laravel/blob/main/README.md Run these commands to install the package and publish its migrations. The migrations are not loaded automatically, so you must publish them. Also publish the companion packages' migrations. Set FORMS_KEY_TYPE before migrating if your senders have UUID/ULID keys. ```bash 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 ``` -------------------------------- ### Define a multi-step form with groups and fields Source: https://github.com/roundly-consulting/forms-for-laravel/blob/main/README.md Use the Forms facade to define a form with a unique key and title. Add groups (steps) and fields with validation rules. The example creates a 'contact' form with two groups: 'details' and 'message'. ```php 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 submit a form submission Source: https://github.com/roundly-consulting/forms-for-laravel/blob/main/README.md Validate a request against a form's rules and store the submission. Input is keyed by form.group.field (e.g., contact.details.name). Forms::validate throws ValidationException on failure. The result's uuid is the submission's reference id. ```php $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 submission answers as typed values Source: https://github.com/roundly-consulting/forms-for-laravel/blob/main/README.md Retrieve submissions for a form and access the answers. The values property returns an array keyed by field name, with typed values. ```php $answers = Forms::submissions($form)->latest()->get(); $answers->first()->values; // ['name' => 'Jane', 'email' => 'jane@example.com', 'body' => 'Hello!'] ```