lexal/laravel-stepped-form
Composer 安装命令:
composer require lexal/laravel-stepped-form
包简介
Stepped Form for Laravel.
README 文档
README
The package is based on the HTTP Stepped Form and built for Laravel framework.
Table of Contents
Requirements
PHP: >=8.2
Laravel: ^11.0 || ^12.0
Installation
Via Composer
composer require lexal/laravel-stepped-form
(back to top)
Configuration
Publish the config
Run the following command to publish the package config file:
php artisan vendor:publish --provider="Lexal\LaravelSteppedForm\ServiceProvider\ServiceProvider"
Available config options
The configuration file config/stepped-form.php has the following options:
renderer- contains Renderer class, instance or service alias that translates step's template definition into the response. Must implementLexal\HttpSteppedForm\Renderer\RendererInterface;redirector- contains Redirector class, instance or service alias that redirects user between form steps. Must implementLexal\HttpSteppedForm\Routing\RedirectorInterface;event_dispatcher- contains Event Dispatcher class, instance or service alias that dispatches form events. Must implementLexal\SteppedForm\EventDispatcher\EventDispatcherInterface;exception_normalizers- contains exception normalizers that the form uses for normalizing SteppedFormException into the Response instance. Read more about them in the HTTP Stepped Form docs;forms- contains array of all application forms definitions. Form definition must have builder class for dynamic forms or array of steps for the static forms, settings class and storage where the form stores its data.
Usage
-
Replace redirector, renderer and event dispatcher with your own implementation and add custom exception normalizers, if necessary.
-
Declare form settings.
use Lexal\HttpSteppedForm\Settings\FormSettingsInterface; use Lexal\SteppedForm\Step\StepKey; final class FormSettings implements FormSettingsInterface { public function getStepUrl(StepKey $key): string { // return step URL } public function getUrlBeforeStart(): string { // returns a URL to redirect to when there is no previously renderable step } public function getUrlAfterFinish(): string { // return a URL to redirect to when the form was finishing } } $formSettings = new FormSettings();
-
Add forms definitions.
- Static form
return [ // ... 'forms' => [ 'customer' => [ 'steps' => [ 'customer' => CustomerStep::class, 'broker' => BrokerStep::class, 'confirmation' => ConfirmationStep::class, // other steps ], 'settings_class' => FormSettings::class, 'storage' => SessionStorage::class, 'session_key_storage' => SessionSessionKeyStorage::class, ], ], // ... ];
- Dynamic form
return [ // ... 'forms' => [ 'customer' => [ 'builder_class' => CustomBuilder::class, 'settings_class' => FormSettings::class, 'storage' => SessionStorage::class, 'session_key_storage' => SessionSessionKeyStorage::class, ], ], // ... ];
- Static form
-
Use Stepped Form in you controller. Stepped Form service is registered under "stepped-form.{{form key}}" alias in the container.
ServiceProvider.php
use Lexal\HttpSteppedForm\SteppedFormInterface; $this->app->when(CustomerController::class) ->needs(SteppedFormInterface::class) ->give('stepped-form.customer');
CustomerController.php
use Lexal\HttpSteppedForm\SteppedFormInterface; final class CustomerController { public function __construct(private readonly SteppedFormInterface $form) { } // POST /customers public function start(): Response { return $this->form->start(new Customer(), /* nothing or customer id to split different sessions */); } // GET /customers/step/{step-key} public function render(string $key): Response { return $this->form->render($key); } // POST /customers/step/{step-key} public function handle(Request $request, string $key): Response { return $this->form->handle($key, $request); } // POST /customers/cansel public function cancel(): Response { return $this->form->cancel(route('customer.index')); } }
See configuration file for more information.
(back to top)License
Laravel Stepped Form is licensed under the MIT License. See LICENSE for the full license text.
lexal/laravel-stepped-form 适用场景与选型建议
lexal/laravel-stepped-form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 489 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「multi-step」 「stepped-form」 「multi-step form」 「dynamic stepped-form」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lexal/laravel-stepped-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lexal/laravel-stepped-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lexal/laravel-stepped-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Implementation of the Stepped Form
HTTP based Stepped Form.
Alfabank REST API integration
Laravel Step validator.
Laravel package for Accurate Online API integration.
Dcat Admin multi-step form extension
统计信息
- 总下载量: 489
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-16