承接 webard/nova-havingable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webard/nova-havingable

最新稳定版本:v1.1.0

Composer 安装命令:

composer require webard/nova-havingable

包简介

Havingable macro for Laravel Nova fields, allowing filtering of aggregated values.

README 文档

README

Allow filtering of values calculated by aggregate functions like withSum, withCount, etc.

Installation

composer require webard/nova-havingable

Description

Let’s say you have a Resource that calculates aggregated values, such as an Order resource that calculates the total amount of ordered products:

class Order extends Resource
{
    public static $model = \App\Models\Order::class;

    public static function indexQuery(NovaRequest $request, $query)
    {
        return $query
            ->withSum('lines', 'amount')
            ->withSum('lines', 'quantity');
    }

    public function resourceFields(NovaRequest $request): array
    {
        return [
            ID::make('ID', 'id'),

            Number::make('Items Sum', 'lines_sum_quantity')
                ->sortable()
                ->exceptOnForms(),

            Number::make('Amount Sum', 'lines_sum_amount')
                ->sortable()
                ->exceptOnForms(),
        ];
    }
}

If you want to make these fields filterable, the filterable() method doesn’t work because it is based on the WHERE clause instead of HAVING.

This package provides a havingable() macro for fields, making them available for filtering.

Usage

Simply add the ->havingable() method to your Resource field:

Number::make('Items sum', 'lines_sum_quantity')
    ->sortable()
    ->exceptOnForms()
    ->havingable()

TODO

  • add tests

Contributing

We welcome contributions to improve this plugin! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive messages.
  4. Push your changes to your forked repository.
  5. Open a pull request to the main repository.

License

This project is licensed under the MIT License. See the LICENSE.md file for more details.

Contact

For questions or support, please open an issue on GitHub.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-22