PHP code example of hasnath / queryable
1. Go to this page and download the library: Download hasnath/queryable 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/ */
hasnath / queryable example snippets
HasnatH\Queryable\Providers\QueryableServiceProvider::class
return [
'filter' => [
'separator' => env('QUERYABLE_FILTER_SEPARATOR', ',')
],
'orderBy' => [
'separator' => env('QUERYABLE_ORDER_BY_SEPARATOR', ',')
],
];
use App\User;
use HasnatH\Queryable\Queryable;
class UserService
{
protected $queryable;
public function index()
{
$queryable = new Queryable(User::class);
$query = User::query();
$query = $queryable->filter($query, request()->get('filter'));
$query = $queryable->orderBy($query, request()->get('orderBy'));
return $query->get();
}
}
public static $filterable = [
'first_name',
'last_name'
];
$query = User::query();
$query = auth()->user();
[
"FIELD,VALUE,OPERATOR",
]
[
["first_name,John"],
["last_name,Smith"]
]
[
["first_name|John"],
["last_name|Smith"]
]
public static $orderable = [
'first_name',
'last_name'
];
$query = User::query();
$query = auth()->user();
[
"FIELD,ORDER",
]
[
["first_name"],
["last_name,DESC"]
]
[
["first_name"],
["last_name|DESC"]
]
text
Laravel
PHP 7
bash
php artisan vendor:publish --provider="HasnatH\Queryable\Providers\QueryableServiceProvider"