PHP code example of ionext / laravel-api-query-parser
1. Go to this page and download the library: Download ionext/laravel-api-query-parser library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ionext / laravel-api-query-parser example snippets
'providers' => [
...
ApiQueryParser\Provider\RequestQueryParserProvider::class,
...
];
// app/API/V1/Models/UserController.php
namespace App\Api\V1\Http\Controllers;
use App\Models\User;
use App\Api\V1\Resources\UserResource;
use App\Api\V1\Resources\UserResourceCollection;
use ApiQueryParser\ResourceQueryParserTrait;
use ApiQueryParser\BuilderParamsApplierTrait;
class UserController extends Controller
{
use ResourceQueryParserTrait;
use BuilderParamsApplierTrait;
public function index(Request $request)
{
$params = $this->parseQueryParams($request);
$query = User::query();
$paginator = $this->applyParams($query, $params);
return UserResourceCollection::make(
$paginator
);
}
}