Giter VIP home page Giter VIP logo

pimpable's Issues

Generating wrong sql code

I got the following SQL:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort' in 'where clause' (SQL: select * from clientswhereclients.deleted_atis null andsortin (created_at, desc) order bycreated_at desc)

When using return $this->model->pimp()->get(); on my ClientRepository, also I'm using the following url api/clients?sort=created_at,desc

Global search

Is it possible to perform a global search.. i.e instead of
GET /api/posts
?thread_id=42
&text=%awesome%
&created_at=(ge)201403
&user_id=!666
&sort[]=is_active,desc
&sort[]=created_at,desc
&with=user

can the get request be like GET /api/posts?search=%awesome%

Pagination and current query addition

Have you every thought of implementing helper functions to find out which conditions are already being applied in the query string.
When I try to use pagination and multiple filters I end up mistakenly overriding old filters from the query string.

function isPimpable(Model $model)
{
    return isSortable($model) || isWithable($model) || isSearchable($model);
}

function isSortable(Model $model)
{
    return array_intersect(
        [Jedrzej\Sortable\SortableTrait::class],
        class_uses($model))
        ? true : false;
}

function isWithable(Model $model)
{
    return array_intersect(
        [Jedrzej\Withable\WithableTrait::class],
        class_uses($model))
        ? true : false;
}

function isSearchable(Model $model)
{
    return array_intersect(
        [Jedrzej\Searchable\SearchableTrait::class],
        class_uses($model))
        ? true : false;
}

There can be addiotnal function to actually track down the current status and just append new ones, or remove old ones.

function getSortable()
{
    /** @TODO: get the proper 'sort' parameter name */
    return ['sort' => Request::query('sort')];
}

function getSearchable(Model $model)
{
    $searchable = [];

    if (method_exists($model, 'getSearchableAttributes')) {
        $searchable = $model->getSearchableAttributes();
    }

    if (property_exists($model, 'searchable')) {
        $searchable = $model->searchable;
    }

    return array_intersect(array_keys(Request::query()), $searchable);
}

Is this an issue ?

Getting when trying this

ErrorException in Arr.php line 94: array_flip(): Can only flip STRING and INTEGER values!

$this->order
->with($relations)
->pimp(null, ['sort[]' => 'id,asc']);

works fine when I use some array instead of null in the first argument

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.