jedrzej / pimpable Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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%
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
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);
}
@jedrzej I think you forgot to create a new tag 0.0.6 ...
I got the following SQL:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sort' in 'where clause' (SQL: select * from
clientswhere
clients.
deleted_atis null and
sortin (created_at, desc) order by
created_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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.