定制 awstalib/filterable-qm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

awstalib/filterable-qm

最新稳定版本:2.0.1

Composer 安装命令:

composer require awstalib/filterable-qm

包简介

Filterable Query or model Package

README 文档

README

FilterableQm is a Laravel package that provides traits for filtering and paginating Eloquent models seamlessly. It includes the FilterableQm trait for filtering models and the PaginateQm trait for easy pagination.

Installation

You can install the package via Composer. Run the following command:

composer require awstalib/filterable-qm 

Usage

FilterableQm Trait In your Eloquent model, use the FilterableQm trait:

use Awstalib\FilterableQm\FilterableQm;

class YourModel extends Model
{
    use FilterableQm;

    // Your model logic here
}

Use the applyFilters method on your model's query builder:

$filteredData = YourModel::query()->applyFilters($filters)->get();

PaginateQm Trait In your Eloquent model, use the PaginateQm trait:

use Awstalib\FilterableQm\PaginateQm;

class YourModel extends Model
{
    use PaginateQm;
    protected $filterItem=['col1','col2'];
     // Your model logic here
    //You can extend filter with your own filter
    public function extendedFilter($query, $filterItem, $value)
    {
        if ($filterItem === 'account_currency' && !empty($value)) {
            $query->whereHas('account', function ($query) use ($value) {
                $query->where('currency_id', $value);
            });
        }
        if($filterItem === 'account_number' && !empty($value)) {
            $query->whereHas('account', function ($query) use ($value) {
                $query->where('account_number', $value);
            });
        }
        return $query;
    }
   
}

Utilize the paginateModel method in your controller:

public function index(Request $request)
{
    $data = $this->paginateModel(new YourModel(), $request, false);
    return ApiResponse::success($data->data, 'Data retrieved successfully', null, $data->count);
}

Version History

1.0.0 (January 7, 2024)

  • Initial release.
  • Added FilterableQm and PaginateQm traits.
  • Basic filtering and pagination functionality.

Contributing

Feel free to contribute to this project by forking it and creating a pull request.

License

This package is open-source and available under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-24