Comments (5)
Firstly, thanks for proposal @robsontenorio :)
But I did not understand actually why do you need it, sorry. I will be glad if you explain using an example case.
from laravel-api-query-builder.
I have my "list all" methods encapsulated in Models. They are encapsulated, because sometimes i can do some custom queries, like: get relations , order by ... not only LIST ALL.
// Games.php - Chess, Mario , Kings ...
public function listAll($request){
// return api query builder results
}
Other methods in here: save, delete, update ...
// Platforms.php - PS4, XboxOne
public function listAll($request){
// return api query builder results
}
Other methods in here: save, delete, update ...
// Player.php - usernames ...
public function listAll($request){
// return api query builder results
}
Other methods in here: save, delete, update ...
So in my endpoint mysite.com/top
i would like to show the top records from some entities.
// RecentController.php - list recent records
public function index(Request $request){
$player = Player::listAll($request); // recent players: limit=5&order_by=id,desc
$games = Game::listAll($request); // recent games added: limit=20&order_by=id,desc
$plataforms = Game::listAll($request); //recent plataforms added: limit=10&order_by=id,desc
// return mounted json
}
In this scenario above my "list all" method have different behavior depending on parameters. By using current implementation ($request object) i cant use custom filters, because all of them depends on the single $request object.
By, using "array of parameters" in QueryBuilder i can build custom queries. It would be an "untied implementation".
public function index(Request $request){
// using custom params
$player = Player::listAll(['limit' => 5, ....]); // recent players: limit=5&order_by=id,desc
$games = Game::listAll(['limit' => 20, ....]); // recent games added: limit=20&order_by=id,desc
$plataforms = Game::listAll(['limit' => 10, ....]); //recent plataforms added: limit=10&order_by=id,desc
// return mounted json
}
I'm currently using this approach. I've changed QueryBuilder.php
constructor and simple changes in related classes.
This "breaking change" allow people to use your lib simple changing $request
parameter to $request->all()
:
new QueryBuilder(new User(), $request->all()))->build()->paginate();
Or in other custom scenario:
$params = []
new QueryBuilder(new User(), $params))->build()->paginate();
from laravel-api-query-builder.
QueryBuilder -> construct
public function __construct(Model $model, array $params = []) {
....
$this->uriParser = new UriParser($params);
....
UriParser -> construct
public function __construct(array $params = []) {
....
$this->uri = (count($params) > 0) ? '?' . http_build_query($params) : NULL;
....
from laravel-api-query-builder.
@robsontenorio I commented to pull request. (#19) Please check it :)
from laravel-api-query-builder.
I created different solution. You can check it from here 2a85dea
I will documented it.
I hope you like new solution :)
By the way thanks for idea @ili5 and @robsontenorio
Shortly you can use it like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Unlu\Laravel\Api\QueryBuilder;
use Unlu\Laravel\Api\RequestCreator;
use App\User;
class UsersController extends Controller
{
public function index()
{
$request = RequestCreator::createWithParameters([
'name' => 'selahattin',
'email' => '[email protected]'
]);
$qBuilder = new QueryBuilder(new User, $request);
return response()->json([
'data' => $qBuilder->build()->get()
]);
}
}
from laravel-api-query-builder.
Related Issues (20)
- How create a new Custom orderBy?
- Adding additional 'where' clause HOT 3
- Laravel 5 autoload serviceproviders HOT 6
- Eloquent lists() deprecated HOT 1
- RequestCreator
- Laravel 5.5 - Undefined index: PATH_INFO HOT 1
- pivots relation HOT 1
- No support for multiple database connections HOT 1
- Soft Deletes HOT 1
- How implement the new Laravel 5.5 feature API Resources?
- Date= and date between not giving proper results
- Modifying the Query before Building HOT 1
- Undefined index: PATH_INFO {"exception":"[object] (ErrorException(code: 0): Undefined index: PATH_INFO at vendor/unlu/laravel-api-query-builder/src/RequestCreator.php:36)
- add select. ?includes=schedules,scheduleExams&code=15207100025&columns=schedules.name
- Refactor QueryBuilder
- Make ready for Laravel 6.0
- Make package of code HOT 1
- Using resources
- Not working if the searching key word includes "&" character
- Method `\Unlu\Laravel\Api\QueryBuilder::paginate()` does not work
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-query-builder.