1. Go to this page and download the library: Download awstalib/filterable-qm 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/ */
awstalib / filterable-qm example snippets
bash
use Awstalib\FilterableQm\PaginateQm;
class YourModel extends Model
{
use PaginateQm;
protected $filterItem=['col1','col2'];
// Your model logic here
//You can extend filter with your own filter
public function extendedFilter($query, $filterItem, $value)
{
if ($filterItem === 'account_currency' && !empty($value)) {
$query->whereHas('account', function ($query) use ($value) {
$query->where('currency_id', $value);
});
}
if($filterItem === 'account_number' && !empty($value)) {
$query->whereHas('account', function ($query) use ($value) {
$query->where('account_number', $value);
});
}
return $query;
}
}
bash
public function index(Request $request)
{
$data = $this->paginateModel(new YourModel(), $request, false);
return ApiResponse::success($data->data, 'Data retrieved successfully', null, $data->count);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.