自定义 Laravel Nova 破坏性动作模式

问题描述 投票:0回答:2
我正在使用

documentation 在 Laravel Nova 中定义一个新的破坏性操作,我想知道是否可以自定义模式消息,即“您确定要运行此操作吗”。

到目前为止,我所能做的就是通过执行以下操作将此消息替换为字段:

public function fields() { return [ Text::make('This is a test field') ]; }
但这会弹出一个文本字段供用户填写。我怎样才能在这里只显示文本,而不需要用户输入字段?

laravel laravel-nova
2个回答
2
投票
根据 Laravel Nova

releasenotes,从 2.5.0 版本开始你可以自定义动作模式的确认。

覆盖 Action 类中的

$confirmText

 属性。

例如:

class YourAction extends Action { /** * The text to be used for the action's confirmation text. * * @var string */ public $confirmText = 'Your confirmation text?'; }
    

0
投票
正如 @saumini-navaratnam 提到的,您可以在操作中指定

$confirmText

。如果你希望它为空,那么你只需使用以下代码:

class YourAction extends Action { public $confirmText = null; }
此外,您还可以使用 

Heading

 字段在表单中显示 html 文本。有关这方面的信息可以在 
https://nova.laravel.com/docs/resources/fields.html#heading-field 找到。

Heading::make('<p class="text-danger">* All fields are required.</p>')->asHtml(),

Heading

字段的好处是它们也会自动从资源索引页面隐藏。我知道这不适用于操作,但它对于资源页面很有用。

© www.soinside.com 2019 - 2024. All rights reserved.