liqrgv / query-filter-laravel Goto Github PK
View Code? Open in Web Editor NEWChange your Request into Query builder
License: Apache License 2.0
Change your Request into Query builder
License: Apache License 2.0
users?include=posts,roles
Hi @LIQRGV, if I may propose for a new feature, how if we support to use a query builder by allowing users to set a table name. I am thinking we have something like this:
public function index(RequestParser $parser)
{
$builder = $parser->setTable('users')->getBuilder();
// do something with builder
}
Then we will get this query behind the scene:
DB::table('users');
If this is acceptable to you, I can contribute to prepare the PR.
Thanks.
We should able transform this query param:
x_model?limit=100&offset=100&filter[z][in]=1,2,3
into this filter
...... where z in (1,2,3) limit 100 offset 100;
Let's say we have this model
class XModel extends Model {
public function Y() {
return $this->belongsTo(Y::class);
}
}
and this query param:
x_model?filter[y][is]=1&filter[y.xcid][is]=2
then, we will have this kind of filter
...... where y.id = 1 and y.xcid is 2;
As enhancement for #3, we should allow "or" filter to use another keyword too.
Currently we have this filter keyword:
private static $WHERE_QUERY_MAPPING = [
"in" => "whereIn",
"!in" => "whereNotIn",
"between" => "whereBetween",
];
So, basically we should able transform this query param:
x_model?filter[a|b][is]=1&filter[c|d][in]=1,2,3&filter[e|f][!in]=4,5,6&filter[g|h][between]=7,8&filter[i][between]=9,10
into this filter
...... where
(a = 1 or b = 1) and
(c in (1,2,3) or d in (1,2,3)) and
(e not in (4,5,6) or f not in (4,5,6)) and
(g between 7 and 8 or h between 7 and 8) and
i between 9 and 10;
Hi @LIQRGV, I see this RequestParser
class is guessing the model name by the current controller name. I think we need to allow user to set the model name with something like setModel
method. let's say we have an App\User
model, then in our controller:
public function index(RequestParser $parser)
{
$builder = $parser->setModel(User::class)->getBuilder();
// do something with builder
}
If you agree, I can prepare a PR for this feature.
Thanks.
We should able transform this query param:
x_model?filter[x|y][is]=1&filter[z][in]=1,2,3
into this filter
...... where (x = 1 or y = 1) and z in (1,2,3);
Hi @LIQRGV, I am using this package and try to fetch 13k records, and they loaded as my expectation. But I think it would be nice if we have a default pagination limit. I am thinking some of these terms:
null
, means no limit.<?php
namespace App\Http\Requests;
use Illuminate\Http\Request;
use LIQRGV\QueryFilter\RequestParser;
class BrowseInvoice extends RequestParser
{
protected $pageLimit = 50;
public function __construct(Request $request)
{
parent::__construct($request);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.