承接 larahook/distinct-on-pagination 相关项目开发

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

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

larahook/distinct-on-pagination

最新稳定版本:v1.1.5

Composer 安装命令:

composer require larahook/distinct-on-pagination

包简介

ORM Multiple distinct() with paginate()

README 文档

README

Multiple distinct(['field_a', 'field_b']) with paginate()

Problem

  • ORM select return error when calculate total rows for pagination
SomeModel::select(['*'])
    ->distinct(['field_a', 'field_b'])
    ->orderBy('field_a')
    ->orderBy('field_b')
    ->paginate($perPage)
  • Exception example
SQLSTATE[42883]: Undefined function: 7 ERROR: function count(bigint, bigint) does not exist\nLINE 1: select count(distinct \"field_a\", \"field_b\") as aggregate from \"...\n

Install

composer require larahook/distinct-on-pagination

Usage

  • Add DistinctOnPagination trait in SomeModel class
  • Pagination total must be calc without Exception
class SomeModel extends Model
{
    use DistinctOnPagination; // <-- add DistinctOnPagination trait
    use HasFactory;

    /** @var string */
    protected $table = 'some_table';
}

Config

  • You can also publish the config file to change implementations (concat delimiter)
php artisan vendor:publish --provider="Larahook\DistinctOnPagination\DistinctOnPaginationServiceProvider" --tag=config

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-15