armincms / wizard
此包已被废弃且不再维护。未建议替代包。
laravel nova 的向导表单。
0.1.1
2020-01-21 11:39 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2020-06-16 11:08:23 UTC
README
wizard
laravel nova 的向导表单
目录
简介
wizard
允许您通过验证每个步骤来逐步创建或更新资源。
安装
要开始使用 Bios,请运行以下命令
composer require armincms/wizard
资源配置
如果您想使用向导表单来编辑资源,必须在资源中添加以下方法
/**
* Get meta information about this resource for client side comsumption.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public static function additionalInformation(Request $request)
{
return ['wizard' => true];
}
然后,为了定义步骤,可以使用 Armincms\Wizard\Step
,如下面的示例所示
use Armincms\Wizard\Step;
calss MyResource extends Resource
{
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
// some fields
Step::make('Step One', [
// step one fields
]),
Step::make('Step Two', [
// step two fields
]),
Step::make('Step Three', [
// step three fields
]),
];
}
}
现在,您的资源将自动显示向导表单。
关于实现
在内部,Armincms \ Wizard \ Step
是一个面板。因此,在进入下一步时,该面板以及之前步骤中的所有字段应通过验证规则。如果验证失败,将显示包含未验证属性的第一个面板。
如果您想在每个步骤上验证某些字段,应定义这些字段而不使用 Armincms\Wizard\Step
,如下所示
use Armincms\Wizard\Step;
calss MyResource extends Resource
{
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
// bellow fields will be validated per each step
Text::make("Text"),
Text::make("Test"),
// and some other fields
// bellow fields will be validated on the active step
Step::make('Step One', [
// step one fields
]),
Step::make('Step Two', [
// step two fields
]),
Step::make('Step Three', [
// step three fields
]),
];
}
}