1. Go to this page and download the library: Download kalimulhaq/qubuilder 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/ */
kalimulhaq / qubuilder example snippets
return [
// When false: `select` becomes rd is rejected, and the builder
// falls back to the model's primary key when no columns are given.
'allow_select_all' => true,
// When false: the `meter Names
|--------------------------------------------------------------------------
| Customise the URL parameter names the package reads from the request.
| Set a key to null to use the default name shown in the comments.
*/
'params' => [
'select' => null, // default: 'select'
'filter' => null, // default: 'filter'
'
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
$builder = User::where('tenant_id', $tenantId);
$users = Qubuilder::make($filters, $builder)->query()->paginate();
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
// GET /api/users?filter={"AND":[{"field":"status","op":"=","value":"active"}]}&sort={"created_at":"desc"}&limit=20
// POST /api/users { "filter": {"AND":[{"field":"status","op":"=","value":"active"}]}, "sort": {"created_at":"desc"}, "limit": 20 }
$users = Qubuilder::makeFromRequest(request(), User::class)
->query()
->paginate();
use Kalimulhaq\Qubuilder\Http\Requests\GetCollectionRequest;
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
class ListUsersRequest extends GetCollectionRequest {}
public function index(ListUsersRequest $request)
{
return Qubuilder::make($request->filters(), User::class)
->query()
->paginate();
}
// On your model:
public function commentable(): MorphTo
{
return $this->morphTo();
}
// Must be public — the package calls this method on your model instance.
public function commentableMap(): array
{
return [
'post' => ['author', 'tags'],
'video' => ['channel'],
];
}
use Kalimulhaq\Qubuilder\Http\Requests\GetCollectionRequest;
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
public function index(GetCollectionRequest $request)
{
return Qubuilder::make($request->filters(), User::class)
->query()
->paginate();
}
use Kalimulhaq\Qubuilder\Http\Requests\GetCollectionRequest;
class ListUsersRequest extends GetCollectionRequest
{
public function authorize(): bool
{
return $this->user()->can('viewAny', User::class);
}
public function rules(): array
{
return array_merge(parent::rules(), [
'search' => ['sometimes', 'string', 'max:100'],
]);
}
}
use Kalimulhaq\Qubuilder\Rules\ValidateFilter;
use Kalimulhaq\Qubuilder\Support\Helper;
public function rules(): array
{
return [
Helper::param('filter') => ['sometimes', new ValidateFilter],
// ... your own rules
];
}
use Kalimulhaq\Qubuilder\Http\Requests\GetResourceRequest;
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
public function show(GetResourceRequest $request, int $id)
{
return Qubuilder::make($request->filters(), User::class)
->query()
->findOrFail($id);
}
use Kalimulhaq\Qubuilder\Support\Facades\Qubuilder;
public function index(ListUsersRequest $request)
{
$builder = User::query()->where('tenant_id', auth()->user()->tenant_id);
return Qubuilder::make($request->filters(), $builder)
->query()
->paginate();
}