johannesschobel / dingoquerymapper Goto Github PK
View Code? Open in Web Editor NEWUses Dingo/API Request Query Parameters to filter Laravel Models
License: MIT License
Uses Dingo/API Request Query Parameters to filter Laravel Models
License: MIT License
Create a buildFromCollection()
method
Create a buildFromModel()
method
how do i limit from which fields i can filter
instead of typing database field name in the url.. i wanna map a parameter passed to url to actual database field name...
is this achievable ?
if so could you tell me how ?
Hi,
How can I use Filtering for Nested response ?
See this :
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "[email protected]",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
},
{
"id": 3,
"name": "Clementine Bauch",
"username": "Samantha",
"email": "[email protected]",
"address": {
"street": "Douglas Extension",
"suite": "Suite 847",
"city": "McKenziehaven",
"zipcode": "59590-4157",
"geo": {
"lat": "-68.6102",
"lng": "-47.0653"
}
},
"phone": "1-463-123-4447",
"website": "ramiro.info",
"company": {
"name": "Romaguera-Jacobson",
"catchPhrase": "Face to face bifurcated interface",
"bs": "e-enable strategic applications"
}
},
{
"id": 4,
"name": "Patricia Lebsack",
"username": "Karianne",
"email": "[email protected]",
"address": {
"street": "Hoeger Mall",
"suite": "Apt. 692",
"city": "South Elvis",
"zipcode": "53919-4257",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "493-170-9623 x156",
"website": "kale.biz",
"company": {
"name": "Robel-Corkery",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
}
]
My controller:
$users = User::with('address')->with('company')->get();
$qm = new DingoQueryMapper($request);
$users = $qm->createFromCollection($users)->paginate();
I need retrieve city based on query I enter in URL, ex:
{{host}}/api/users?address[city]=Jakarta
Its not working, is still retrieve all of user data.
Can you help me for nested filtering ?
Edit (johannessschobel):
I have removed some entities in order to "shrink" down the issue message.
Hello, I am trying to do a search on a column named 'customername', but the values in the database are either uppercase or lowercase, is there any way to do a case INSENSITIVE search?
{{url}}/loads?sort=id&limit=100&customername=TORRES*
^ This will bring back records with 'TORRES' in the customername but not records with the a lower case 'torres'.
How can i get specific columns in DingoQueryMapperBuilder
code like below :
$orders = Order::whereNotNull('id');
$qm = new DingoQueryMapperBuilder($request);
return $qm->createFromBuilder($orders)->paginate()
Hey,
I've noticed this package isn't compatible with PSR2 code standards.
I've gone ahead and forked to make it comparable.
propose the limit=0
parameter in order to disable limits..
Hey,
Is it possible to sort relations?
e.g /api/v1/events?sort=team.name or /api/v1/events?sort=team[name]
I've tried using both but they seem to throw errors.
Cheers
Well, another one @johannesschobel :)
When working with the custom filters you now have the possibility to filter on strings 'starting with' using the String* filter. I have a lot of cases where I need a bit more fuzzy matching, for example matching a part of a string: 'A beautiful song I wrote'.
I would suggest expanding the createEvaluationRule method, listening for *String*, to fit this purpose?
private function createEvaluationRule($key, $operator, $value)
{
// first, check the operator type!
if ($operator == '=') {
$operator = '==';
}
// escaping
$key = addslashes($key);
$rule = "'%s' %s '%s'"; // key, operator, value
$rule = sprintf($rule, $key, $operator, $value);
// now check if the operator was "(not) like"?
if (strpos($operator, 'like') !== false) {
// check for %value% to perform a more fuzzy match
if (preg_match('/%(.*).{1,}?%/', $value)) {
$value = str_replace('%', '', $value);
$rule = "%sis_int(stripos('%s', '%s')) ? true : false";
$expectedResult = '';
if (stripos($operator, 'not') !== false) {
// it is a NOT LIKE operator
$expectedResult = '!';
}
$rule = sprintf($rule, $expectedResult, $key, $value);
} else {
$value = str_replace('%', '', $value);
$rule = "substr('%s', 0, strlen('%s')) %s '%s'"; // haystack, $needle, $comparable, $needle
$expectedResult = '===';
if (stripos($operator, 'not') !== false) {
// it is a NOT LIKE operator
$expectedResult = '!==';
}
$rule = sprintf($rule, $key, $value, $expectedResult, $value);
}
}
return $rule;
}
If you like the idea I can send in another PR?
Hence this looks really simple to use
How about adding support for laravel 5.4 ? :)
Hey,
I'm using this package in a project and I've just run into an issue where I need to get results where a column is null (and also not null).
I'm happy to do the PR for it, but I'm wondering what operators you'd suggest/rather have.
I encountered an issue when filtering a Collection using the createFromCollection method from your DingoQueryMapper. When there are model params with single quoted content, building the filtering rules seems to break.
I think the problem is in the createEvaluationRule method from the CollectionOperator. When building an evaluation rule, where the key contains a single quote, the endresult is a string which cannot be evaluated. I can solve this by stripping any single quotes from the $key parameter, before further building the rule in createEvaluationRule.
Just to be sure, am I doing something wrong here or did I just found a bug ;). Thanks in advance!
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.