clevyr/nova-action-button

一个Laravel Nova字段,用于执行操作。

v1.0.4 2024-08-30 19:50 UTC

This package is auto-updated.

Last update: 2024-08-30 19:51:48 UTC


README

Latest Version on Packagist Licence Total Downloads

此包允许您直接在资源表视图中执行操作。

分支自

https://github.com/pdmfc/nova-action-button

安装

composer require clevyr/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。

Basic example

禁用按钮

您可以使用Laravel nova的本地 readonly() 方法来阻止用户点击按钮

ActionButton::make('Action')
    ->action(ChangeRole::class, $this->id)
    ->readonly(function () {
        return $this->role->name === 'admin';
    })

Disabling the button

更改按钮文本

要编辑按钮文本内容,请使用 text() 方法。

->text('Execute')

在按钮上启用加载动画并更改颜色

要启用按钮上的加载动画并更改颜色,请使用 showLoadingAnimation()loadingColor('#fff') 方法。

->showLoadingAnimation()
->loadingColor('#fff') # default is #000

向按钮添加svg

要向按钮添加svg,您首先需要创建一个包含svg的vue组件,然后将组件名称传递给 svg() 方法。

->svg('VueComponentName')

更改按钮颜色

要更改按钮颜色,请使用 buttonColor('#21b970') 方法。

->buttonColor('#21b970') # default is .btn-primary color

注意事项

  • 目前,为了使用此字段,您仍然需要在资源的 actions() 方法中声明操作。

如何贡献

  • 克隆仓库
  • 在laravel nova应用程序的 composer.json 中添加以下内容
{
    //...

    "require" {
        "clevyr/nova-action-button: "*"
    },

    //...
    "repositories": [
        {
            "type": "path",
            "url": "../path_to_your_package_folder"
        }
    ],
}
  • 运行 composer update clevyr/nova-action-button

现在您已准备好开始贡献了!

变更日志

请参阅 CHANGELOG 以获取有关最近更改的更多信息。