Package Data | |
---|---|
Maintainer Username: | ngekoding |
Maintainer Contact: | blog.nurmuhammad@gmail.com (Nur Muhammad) |
Package Create Date: | 2019-05-22 |
Package Last Update: | 2019-05-22 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:20:11 |
Package Statistics | |
---|---|
Total Downloads: | 16 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
The original package go here:
If you need php5 support, so you can use this package. But if you already using php7, please use the original package.
This is a simple request query parameter parser for REST-APIs based on Laravel's Lumen framework.
$app->register(LumenApiQueryParser\Provider\RequestQueryParserProvider::class);
// app/API/V1/Models/UserController.php
namespace App\Api\V1\Http\Controllers;
use App\Api\V1\Models\User;
use App\Api\V1\Transformers\UserTransformer;
use LumenApiQueryParser\ResourceQueryParserTrait;
use LumenApiQueryParser\BuilderParamsApplierTrait;
class UserController extends Controller
{
use ResourceQueryParserTrait;
use BuilderParamsApplierTrait;
public function index(Request $request)
{
$params = $this->parseQueryParams($request);
$query = User::query();
$userPaginator = $this->applyParams($query, $params);
$this->response->paginator($userPaginator, new UserTransformer, ['key' => 'users']);
}
}
Q: /users?includes[]=profile
R: will return the collection of the users with their profiles included
Q: /users?filter[]=name:ct:admin
R: will return the collection of the users whose names contains the admin string
Available filter options
| Operator | Description | Example | | ------------- | --------------------- | ------- | | ct | String contains | name:ct:Peter | | nct | String NOT contains | name:nct:Peter | | sw | String starts with | username:sw:admin | | ew | String ends with | email:ew:gmail.com | | eq | Equals | level:eq:3 | | ne | Not equals | level:ne:4 | | gt | Greater than | level:gt:2 | | ge | Greater than or equal | level:ge:3 | | lt | Lesser than | level:lt:4 | | le | Lesser than or equal | level:le:3 | | in | In array | level:in:1|2|3 |
Q: /users?sort[]=name:ASC
R: will return the collection of the users sort by their names ascending
Q: /users?limit=10&page=3
R: will return a part of the collection of the users (from the 21st to 30th)