fector/harvest

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple library that provide modify Model by request query

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

A simple library that provide modify Model by request query

Installation

Install the package through composer

composer require fector/harvest

Publish config

php artisan vendor:publish

Once composer finished add the service provider to the providers array in app/config/app.php:

Fector\Harvest\HarvestServiceProvider::class,

Set an alias in app.php:

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

That's it!

Configuration

To override the configuration, create a file called harvest.php in the config folder of your app.
The option combines contains a list of request handlers. Where the key is the query parameter key and the value of the class name that will handle the value.

Usage

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);
}

Default Combines

Sorter

Two ways of sorting: ascending

/api/books?_sort=title

and descending with prefix "-"

/api/books?_sort=-title
Collector

You may specify which relationships should be eager loaded with data. Collector load relation if it exists.

/api/books?_with=authors

or

/api/books?_with=authors,publisher
Selector

You may specify which fields should be loaded.

/api/books?_select=title

or

/api/books?_select=title,publisher

Plan to add new default Combines: Limiter, Skipper, Filter.