selahattinunlu / laravel-api-query-builder

Laravel & Lumen Api Query Builder Package
331 stars 66 forks source link

added params in query builder #19

Closed ili5 closed 7 years ago

ili5 commented 7 years ago

Quick solution for custom param elements

selahattinunlu commented 7 years ago

@ili5 Hey! Thanks for pr. I will check it :)

ili5 commented 7 years ago

I needed that changes for one of my projects, I tried to not change anything crucial in constructors, but if you want you can re-write it in your way :)

robsontenorio commented 7 years ago

@ili5 @selahattinunlu i have a diferent approach as see on. https://github.com/selahattinunlu/laravel-api-query-builder/issues/15 I just use $params (array) instead $request. That allow me do this things like this:

/users/876

I`m quite new on Github, i will try to send a PR.

ili5 commented 7 years ago

@robsontenorio I also tried that way, but I think it's better to have both options

robsontenorio commented 7 years ago

The same issue #15 has other suggestions. If you and the owner could review it would be nice :)

selahattinunlu commented 7 years ago

@robsontenorio @ili5

I checked it. But it does not work as expected. Also, if you want to use "!=" (etc) operator using parameters instead of Request object, a problem occurs.

I understand very well what you want. So, I will create a solution that covers the problem I mentioned above.

selahattinunlu commented 7 years ago

@ili5 @robsontenorio

I created different solution. You can check it from here https://github.com/selahattinunlu/laravel-api-query-builder/commit/2a85dea4ee09046209d09821725f9b1ceb4b97fa

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()
        ]);
    }
}