marshmallow/prefiller-field

一个用于基于另一个字段预填充字段的 Laravel Nova 字段。非常棒!

2.3.1 2023-08-04 15:18 UTC

README

一个用于基于另一个字段预填充字段的 Laravel Nova 字段。非常棒!

安装

composer require marshmallow/prefiller-field

使用

public function fields(Request $request)
{
    return [
		BelongsTo::make('Product')->nullable()->searchable(),

		PrefillerText::make('Test', 'field_2')
                    ->sourceField('product')
                    ->sourceModel(\Marshmallow\Product\Models\Product::class)
                    ->prefillWith('name'), // This can be a field or a method on your target resource

        PrefillerCurrency::make('Test 3', 'field_3')
                    ->sourceField('product')
                    ->sourceModel(\Marshmallow\Product\Models\Product::class)
                    ->prefillWith('price')
                    ->currency('EUR')
                    ->default(0)
                    ->nullable(),
	]
}

额外方法

如果您希望预填充器检查新值,即使目标字段已经填充了内容,也可以调用 allowUpdatingFilledFields() 方法。

支持

目前我们只实现了 TextCurrency 字段,因为我们需要在客户的项目中使用它。我们将在接下来的几个月内添加更多。如果您需要其他字段用于项目,请随意发送 pull request。

安全

如果您发现任何与安全相关的问题,请通过电子邮件 stef@marshmallow.dev 联系,而不是使用问题跟踪器。

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。