pavloniym/nova-action-buttons 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pavloniym/nova-action-buttons

Composer 安装命令:

composer require pavloniym/nova-action-buttons

包简介

A Laravel Nova field.

README 文档

README

Latest Version on Packagist Licence Total Downloads

This Laravel Nova package allows you to execute an action directly on your resource table view.

Requirements

  • php: >=8.0
  • laravel/nova: ^4.1

Installation

Install the package in a Laravel Nova project via Composer:

composer require pavloniym/nova-action-buttons

Usage

Single button

Nova Action Buttons
You can add single button to execute action from index row

use Pavloniym\ActionButtons\ActionButton;

public function fields(Request $request)
{
    return [
      
        // ... Nova default fields
      
        ActionButton::make('') // Name in resource table column
            ->icon('lightning-bolt') // heroicon name  ->icon('lightning-bolt')
            ->iconHtml('<svg></svg>') // Svg (or html) icon
            ->iconUrl('https://img.com/icon.png') // Url of icon
            ->text('Refresh') // Title (optional)
            ->tooltip('Magic tooltip here') // Tooltip text (optional). If not provided, it will default to the action name.
            ->styles([]) // Custom css styles (optional)
            ->classes([]) // Custom css classes (optional)
            ->action(new RefreshAction, $this->resource->id) // Provide action instance and resource id
            ->asToolbarButton(), // Display as row toolbar button (optional)
      
        // ... Nova default fields
    ];
}

Collection of buttons

Nova Action Buttons
You can add collection of buttons to index row

use Pavloniym\ActionButtons\ActionButton;

public function fields(Request $request)
{
    return [
      
        // ... Nova default fields
      
        ActionButtons::make()->collection([
            ActionButton::make('')->action(),
            ActionButton::make('')->action(),
            ActionButton::make('')->action(),
        ])
      
        // ... Nova default fields
    ];
}

This fields (both ActionButton and ActionButtons) are available on index and detail (Thanks to @CosminBd) views

Caveats

  • Currently, in order to use this field, you still have to declare the action in your resource actions() method.
  • Tested only on confirm-action-modal action
  • You should provide action instance in action() method of button.
  • If you have action fields that are depends on resource instance -> you should inject resource in action constructor, because Nova doesn't provide NovaRequest instance to fields method on index row
class RefreshAction extends Action 
{

    private Torrent $torrent

    /**
     * @param Torrent $torrent
     */
    public function __construct(Torrent $torrent)
    {
        $this->torrent = $torrent;
    }


    
    /**
     * Get the fields available on the action.
     *
     * @param NovaRequest $request
     * @return array|null
     */
    public function fields(NovaRequest $request): ?array
    {
   
        // $request is empty if action is called from index row (or inline)
        // so use instance injected to action constructor
        $torrent = (fn(): ?Torrent => $request?->selectedResources()?->first())();
        $torrent = $torrent ?? $this->torrent;

        if ($torrent) {
            return [
                File::make('File')->creationRules(['required'])
            ];
        }

        return null;
    }

}

To hide the action either on Index or Detail, you can add the methods in the action declaration as per:

ActionButton::make('My action')
    ->action((new RefreshAction)->onlyOnDetail(), $this->resource?->id)
    ->icon('')
    ->asToolbarButton(),

This is available for both action buttons and action button groups, and it works in individual actions which are part of the action group.

To run actions without confirmation, you can add the $withoutConfirmation = true property to the Laravel Nova action or provide it as a method when you declare the action button

ActionButton::make('My action')
    ->action((new RefreshAction)->withoutConfirmation(), $this->resource?->id)
    ->icon('')
    ->asToolbarButton(),

License

This project is open-sourced software licensed under the MIT license.

pavloniym/nova-action-buttons 适用场景与选型建议

pavloniym/nova-action-buttons 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 220.57k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2022 年 12 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 「buttons」 「actions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pavloniym/nova-action-buttons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pavloniym/nova-action-buttons 我们能提供哪些服务?
定制开发 / 二次开发

基于 pavloniym/nova-action-buttons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 220.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 16
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-03