-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Proposal - Use "array of params" instead $request #15
Comments
Firstly, thanks for proposal @robsontenorio :) |
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 ...
// Platforms.php - PS4, XboxOne
// Player.php - usernames ...
So in my endpoint // RecentController.php - list recent records
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".
I'm currently using this approach. I've changed This "breaking change" allow people to use your lib simple changing
Or in other custom scenario:
|
QueryBuilder -> construct
UriParser -> construct
|
@robsontenorio I commented to pull request. (#19) Please check it :) |
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' => '!=blabla@example.com'
]);
$qBuilder = new QueryBuilder(new User, $request);
return response()->json([
'data' => $qBuilder->build()->get()
]);
}
} |
Problem
Sometimes i need to call model`s methods, that uses a QueryBuilder instance. So , i "can not trust" on $request object, in this case. Because, not all parameters in current querystring are applied for both QueryBuilder instances.
Proposal
This is my current implementation, for solve my problem, and i would like to share if you. Its a braking change.
Change QUERYBUILDER.PHP
FROM
__construct(Model $model, Request $request)
TO
__construct(Model $model, array $params = [])
QueryBuilder.php
UriParser.php
Example
MODELS/USER
MODELS/TOURNAMENT
CONTROLLERS/DASHBOARD
The text was updated successfully, but these errors were encountered: