Giter Club home page Giter Club logo

query-filter-laravel's People

Contributors

dependabot[bot] avatar liqrgv avatar nafiesl avatar pmessinezis avatar rizkyarlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

query-filter-laravel's Issues

Allow Table Setter

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.

Allow pagination

We should able transform this query param:
x_model?limit=100&offset=100&filter[z][in]=1,2,3

into this filter

...... where z in (1,2,3) limit 100 offset 100;

Allow filter by relation

Let's say we have this model

class XModel extends Model {
  public function Y() {
    return $this->belongsTo(Y::class);
  }
}

and this query param:
x_model?filter[y][is]=1&filter[y.xcid][is]=2

then, we will have this kind of filter

...... where y.id = 1 and y.xcid is 2;

Add more filter keyword to "or" filter

As enhancement for #3, we should allow "or" filter to use another keyword too.

Currently we have this filter keyword:

    private static $WHERE_QUERY_MAPPING = [
        "in" => "whereIn",
        "!in" => "whereNotIn",
        "between" => "whereBetween",
    ];

So, basically we should able transform this query param:
x_model?filter[a|b][is]=1&filter[c|d][in]=1,2,3&filter[e|f][!in]=4,5,6&filter[g|h][between]=7,8&filter[i][between]=9,10

into this filter

......  where 
            (a = 1 or b = 1) and 
            (c in (1,2,3) or d in (1,2,3)) and 
            (e not in (4,5,6) or f not in (4,5,6)) and 
            (g between 7 and 8 or h between 7 and 8) and 
            i between 9 and 10;

Allow Model Setter

Hi @LIQRGV, I see this RequestParser class is guessing the model name by the current controller name. I think we need to allow user to set the model name with something like setModel method. let's say we have an App\User model, then in our controller:

public function index(RequestParser $parser)
{
    $builder = $parser->setModel(User::class)->getBuilder();
    // do something with builder
}

If you agree, I can prepare a PR for this feature.

Thanks.

Allow filtering with "or" condition

We should able transform this query param:
x_model?filter[x|y][is]=1&filter[z][in]=1,2,3

into this filter

...... where (x = 1 or y = 1) and z in (1,2,3);

Default Pagination Limit

Hi @LIQRGV, I am using this package and try to fetch 13k records, and they loaded as my expectation. But I think it would be nice if we have a default pagination limit. I am thinking some of these terms:

  • We can set a default limit value in a config file.
  • The default pagination limit is null, means no limit.
  • We can create a child RequestParser class, and override the pagination limit with a class property.
<?php

namespace App\Http\Requests;

use Illuminate\Http\Request;
use LIQRGV\QueryFilter\RequestParser;

class BrowseInvoice extends RequestParser
{
    protected $pageLimit = 50;

    public function __construct(Request $request)
    {
        parent::__construct($request);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.