PHP code example of ngabor84 / lumen-api-query-parser

1. Go to this page and download the library: Download ngabor84/lumen-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/ */

    

ngabor84 / lumen-api-query-parser example snippets


    $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']);
        }
    }