lexal / laravel-stepped-form-submitter
Stepped Form submitter for Laravel & Lumen.
Requires
- php: >=8.1
- illuminate/contracts: ^9.0 || ^10.0
- illuminate/support: ^9.0 || ^10.0
- lexal/form-submitter: ^2.0
- lexal/stepped-form: ^2.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-latest
- webimpress/coding-standard: ^1.3
Suggests
- illuminate/config: Required to use Laravel config (^9.0 || ^10.0).
- illuminate/events: Required to listen Stepped Form event (^9.0 || ^10.0).
This package is auto-updated.
Last update: 2024-10-28 23:21:13 UTC
README
The package is based on the Form Submitter and built for the Laravel & Lumen framework.
Table of Contents
Requirements
PHP: >=8.1
Laravel: ^9.0 || ^10.0
Installation
Via Composer
composer require lexal/laravel-stepped-form-submitter
Additional changes for Lumen framework
Add the following snippet to the bootstrap/app.php
file under the providers section as follows:
$app->register(Lexal\LaravelSteppedFormSubmitter\ServiceProvider\ServiceProvider::class);(back to top)
Configuration
Publish the config
Run the following command to publish the package config file:
php artisan vendor:publish --provider="Lexal\LaravelSteppedFormSubmitter\ServiceProvider\ServiceProvider"
Available config options
The configuration file config/form-submitter.php
has the following options:
-
transaction_class
- place a class name, instance or service alias which the FormSubmitter will use to handle transactions. Placenull
or remove config to disable transactions.'transaction_class' => DatabaseTransaction::class,
-
submitters
- specify at least one form submitter that the stepped form will use to submit entity on FormFinished event. Must implementFormSubmitterInterface
.'submitters' => [ // list of form submitters ],
Usage
-
Add form transaction implementation, if necessary.
use Lexal\FormSubmitter\Transaction\TransactionInterface; final class DatabaseTransaction implements TransactionInterface { public function start(): void { // start transaction } public function commit(): void { // commit transaction } public function rollback(): void { // rollback transaction } }
-
Create custom form submitters.
use Lexal\FormSubmitter\FormSubmitterInterface; final class CustomerFormSubmitter implements FormSubmitterInterface { public function supportsSubmitting(mixed $entity): bool { return $entity instanceof Customer; } public function submit(mixed $entity): mixed { // save entity to the database return $entity; } }
-
Update configuration file. Add form submitters and transaction class (if necessary).
return [ 'transaction_class' => DatabaseTransaction::class, 'submitters' => [ CustomerFormSubmitter::class, ], ];
-
Form submitter will call your custom form submitter automatically if it supports submitting of stepped-form entity.
License
Laravel & Lumen Stepped Form Submitter is licensed under the MIT License. See LICENSE for the full license text.