LIQRGV / query-filter-laravel

Change your Request into Query builder
Apache License 2.0
10 stars 2 forks source link

Allow Table Setter #11

Closed nafiesl closed 4 years ago

nafiesl commented 4 years ago

Hi @LIQRGV, if I may propose for a new feature, how if we support to use a query builder by allowing users to set a table name. I am thinking we have something like this:

public function index(RequestParser $parser)
{
    $builder = $parser->setTable('users')->getBuilder();
    // do something with builder
}

Then we will get this query behind the scene:

DB::table('users');

If this is acceptable to you, I can contribute to prepare the PR.

Thanks.

LIQRGV commented 4 years ago

I think for now we're good with using setModel. Could you give me on which use-case this scenario happen ? Because naturally all database should have 1 model, except a pivot of course.

nafiesl commented 4 years ago

I was planned to research a lumen/laravel API application with 1 endpoint which will accept this kind of request params:

page[limit]=100
page[offset]=200
table=users
filter[is_active][is]=1

Basically we will run an SQL query to a table which we can set dynamically from the request param.

LIQRGV commented 4 years ago

Don't you think it's better applied on the controller instead ? It will easily done with setModel. I think it will be bloated if we add table name too on the request.

nafiesl commented 4 years ago

Got it @LIQRGV. I will try to implement it on the controller instead. :+1: