fector/收获

此包已被废弃且不再维护。未建议替代包。

一个简单的库,通过请求查询来修改模型

v0.3.4 2019-01-29 07:22 UTC

This package is not auto-updated.

Last update: 2021-03-20 10:34:38 UTC


README

Build Status

一个简单的库,通过请求查询来修改模型

安装

通过composer安装此包

composer require fector/harvest

发布配置

php artisan vendor:publish

composer完成后,将服务提供者添加到app/config/app.php中的providers数组中

Fector\Harvest\HarvestServiceProvider::class,

app.php中设置别名

'Harvester' => Fector\Harvest\Facades\Harvester::class

就这样!

配置

要覆盖配置,在您的应用配置文件夹中创建一个名为harvest.php的文件。
选项组合包含一个请求处理器的列表。其中键是查询参数键,值是处理该值的类名。

用法

use Fector\Harvest\Facades\Harvester;

/**
 * Display the resource collection
 *
 * @param Request $request
 * @return BooksCollection
 */
public function index(Request $request): BooksCollection
{
    $books = Book::where('status', 1);
    $books = Harvester::recycle($communities)->paginate();
    return new BooksCollection($communities);
}

默认组合

排序器

两种排序方式:升序

/api/books?_sort=title

和降序(前缀为"-")

/api/books?_sort=-title
收集器

您可以指定哪些关系应该与数据一起预加载。如果存在,收集器将加载关系。

/api/books?_with=authors

/api/books?_with=authors,publisher
选择器

您可以指定要加载哪些字段。

/api/books?_select=title

/api/books?_select=title,publisher

计划添加新的默认组合:限制器、跳过器、过滤器。