ahmadaldali / filter-lists

简化列表处理

0.3 2022-04-25 20:33 UTC

This package is auto-updated.

Last update: 2024-09-26 12:43:59 UTC


README

filter-lists 是一个用于处理列表的 Laravel 扩展包。特别是,处理类型为 Illuminate\Database\Eloquent\Collection 的结果。

包含分页响应,并包含以下基本过滤器: page, limit, sort by, desc

// page (integer): get your list with a specific page.
// limit (integer): get your list with a limited number of returned records.
// sortBy (string): sort the results according to a column.
// desc (bool): determine the type of your sort. 

根据模型列包含过滤器。

// e.g: name, email, is_admin, etc ...

根据 "dateRange" 属性包含过滤器。

// get your list that is created between two dates.
{
  "from": "string",
  "to": "string"
}

根据 "fixRange" 属性包含过滤器。

Available values: today, monthly, yearly
// get your list that is created today.
// get your list that is created in the current month.
// get your list that is created in the current year.

.dependencies

laravel/framework: ">=8",

安装

使用 Composer 在项目的根目录中安装此包。

composer require ahmadaldali/filter-lists

使用方法

# use the result's Trait && Request Facade
use AhmadAldali\FilterLists\Traits\ListsResult;
use Illuminate\Http\Request;

#In your controller, or where you want to use the filtering 
$collection = User::all(); #or any model
# then, call getTheResult function
$results = $this->getTheResult($collection , $request);

示例

我在测试应用程序中创建了一个名为 /list 的路由。

在该路由中,我执行了一个包含前面 使用方法 的控制器中的操作。

获取所有结果

alt text

应用限制

alt text

应用带分页的限制

alt text

应用条件

alt text

应用带有错误值的条件

alt text

应用带有错误列名的条件

alt text

贡献

欢迎拉取请求。对于重大更改,请首先创建一个问题以讨论您想要更改的内容。

欢迎任何建议。

许可证

MIT