Comments (9)
Hi
I am almost there
$builder = ApiHandler::parseMultiple($query)->getBuilder();
$queryBuilder = $builder->getQuery();
$queryBuilder->where('project_content.name', 'like', 'Green%');
On thing I don't get is how you would use the except
method.
Any tips?
from laravel-api-handler.
Nope, not yet. All you can do right now is adding the "custom" filter to the query builder yourself after the rest was applied. You can use the getBuilder
method after calling parseSingle
/parseMultiple
to get started.
I'm thinking about a more powerful way to query the data for version 1.0 of the package.
The current approach of filtering is very limited because of the fact that the filter statements are divided in multiple get params and also due to the limitation of parameter key naming. I'm not yet past conceptual work though because of very limited time available for the project.
from laravel-api-handler.
Hi marcelgwerder
Thanks for the fast reply.
Would be nice to have in v1.0
Kinda new to laravel, is there an example available on how to add the custom filter?
from laravel-api-handler.
What you'll get with getBuilder
is a query builder object and you'll thus have all the tools available described in the respective section of the Laravel docs: Database: Query Builder.
You may have to pass the get parameters to the api handler manually because it will otherwise try to add the custom filter to the query of the main table. There is a convenient except
method on the request object. How you can pass the params manually is documented in the readme of the package.
from laravel-api-handler.
You can use the request object to access the get params:
public function index(Request $request)
{
// ...
$builder = ApiHandler::parseMultiple($query, [], $request->except('project_content_name'))->getBuilder();
if ($request->has('project_content_name')) {
$queryBuilder = $builder->getQuery();
$queryBuilder->where('project_content.name', 'like', $request->input('project_content_name').'%');
}
// ...
}
The getQuery
call should actually not be necessary as far as I remember because the EloquentBuilder
should pass all calls to the QueryBuilder
automatically.
from laravel-api-handler.
Hi
When I do it like this http://nanopixel-dashboard.local:8888/api/projects?_config=meta-total-count,meta-filter-count&id=3&project_content_name=f
It still tries to access project.project_content_name:
{
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'project.project_content_name' in 'where clause' (SQL: select count(*) as aggregate from `project` left join `project_content` on `project_content`.`project_id` = `project`.`id` where `project`.`id` = 3 and `project_content`.`name` like %f% and `project`.`id` = 3 and `project`.`project_content_name` = f)",
"code": "42S22",
"status_code": 500
}
The $request->except('project_content_name')
doesn't seem to be ignored.
$builder = ApiHandler::parseMultiple($query, [], $request->except('project_content_name'))->getBuilder();
//$queryBuilder = $builder->getQuery();
if ($request->has('project_content_name')) {
$builder->where('project_content.name', 'like', '%' . $request->input('project_content_name') . '%');
}
from laravel-api-handler.
Never mind, I found the problem.
I had another ApiHandler::parseMultiple()
which I overlooked.
from laravel-api-handler.
Another problem with this solution, the meta information gets lost when I do it like this, its an empty array.
$builder = ApiHandler::parseMultiple($query, [], $request->except(['content_name', 'content_language']))->getBuilder();
// This is a fix to search in other tables.
if ($request->has('content_name')) {
$builder->where('project_content.name', 'like', '%' . $request->input('content_name') . '%');
}
if ($request->has('content_language')) {
$builder->where('project_content.language', '=', $request->input('content_language'));
}
return $builder->get();
from laravel-api-handler.
Hi!, sorry for reopen it. are there a method to solve the problem with meta information?
from laravel-api-handler.
Related Issues (20)
- Add offset, limit and filter to meta HOT 1
- Predefined filter partially not working ? HOT 6
- Transformers / Include related models HOT 1
- Sorting datetime field HOT 4
- Why parseSingle HOT 2
- Returning relationship model data even when not requested when Accessor is used in model HOT 1
- The last version not working with larave 5.3 HOT 2
- better if this package support more than two layer "_fields" nesting HOT 1
- Is there any chance to use with Doctrine?
- Not able to use on Lumen without Facades HOT 1
- Great job! HOT 1
- Non-static method Marcelgwerder\\ApiHandler\\ApiHandler::parseMultiple() should not be called statically HOT 2
- Support for Laravel 5.5 Resources HOT 1
- [question] Use library with repository HOT 2
- How can i use custom get param HOT 3
- Proposal - Appends HOT 1
- Security question HOT 1
- Allow to selectively use soft-deleted entities HOT 1
- [Next] Setting sortable columns does not work properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-api-handler.