kayacekovic / nova-action-button
Laravel Nova 字段,用于运行操作。
v0.7.4
2021-11-05 10:01 UTC
Requires
- php: >=7.1.0
README
此软件包允许您在资源表格视图中直接执行操作。
安装
composer require kayacekovic/nova-action-button
使用
use App\Nova\Actions\ChangeRole; use Pdmfc\NovaFields\ActionButton; //... public function fields() { return [ ActionButton::make('Action') ->action(ChangeRole::class, $this->id) //->action(new ChangeRole(), $this->id) using a new instance ]; }
action()
方法需要两个参数 - 操作类名或一个新实例,以及目标资源ID。
禁用按钮
您可以使用Laravel Nova的本地 readonly() 方法来防止用户点击按钮
ActionButton::make('Action') ->action(ChangeRole::class, $this->id) ->readonly(function () { return $this->role->name === 'admin'; })
修改按钮文本
要编辑按钮文本内容,请使用 text()
方法。
->text('Execute')
在按钮上启用加载动画并更改颜色
要在按钮上启用加载动画并更改颜色,请使用 showLoadingAnimation()
和 loadingColor('#fff')
方法。
->showLoadingAnimation() ->loadingColor('#fff') # default is #000
修改按钮颜色
要更改按钮颜色,请使用 buttonColor('#21b970')
方法。
->buttonColor('#21b970') # default is .btn-primary color
注意事项
- 目前,为了使用此字段,您仍需要在资源的
actions()
方法中声明操作。
如何贡献
- 克隆仓库
- 在laravel nova应用程序的
composer.json
中添加以下内容
{
//...
"require" {
"pdmfc/nova-action-button: "*"
},
//...
"repositories": [
{
"type": "path",
"url": "../path_to_your_package_folder"
}
],
}
- 运行
composer update pdmfc/nova-action-button
您现在可以开始贡献了!
更新日志
请参阅 更新日志 了解最近的变化信息。