All Projects → jedrzej → pimpable

jedrzej / pimpable

Licence: MIT license
No description or website provided.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to pimpable

Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (+10.78%)
Mutual labels:  eloquent, filter, filtering
Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (-25.49%)
Mutual labels:  sorting, filter, filtering
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (-31.37%)
Mutual labels:  sorting, filter, filtering
JqueryDataTablesServerSideDemo
Jquery DataTables with Asp.Net Core server side multi column sorting and searching Demo Project.
Stars: ✭ 43 (-57.84%)
Mutual labels:  sorting, filtering, searching
Muuri React
The layout engine for React
Stars: ✭ 163 (+59.8%)
Mutual labels:  sorting, filter
laravel-filter
Configurable and modular approach to query Filters for Laravel
Stars: ✭ 85 (-16.67%)
Mutual labels:  filter, filtering
React Table
⚛️ Hooks for building fast and extendable tables and datagrids for React
Stars: ✭ 15,739 (+15330.39%)
Mutual labels:  sorting, filtering
algoexpert
AlgoExpert is an online platform that helps software engineers to prepare for coding and technical interviews.
Stars: ✭ 8 (-92.16%)
Mutual labels:  sorting, searching
Blazortable
Blazor Table Component with Sorting, Paging and Filtering
Stars: ✭ 249 (+144.12%)
Mutual labels:  sorting, filtering
DSA--GeeksForGeeks
DSA course solutions in C++ Jump to below directly for more problems
Stars: ✭ 47 (-53.92%)
Mutual labels:  sorting, searching
eloquent-filter
Library to form search criteria through expressions in the query string
Stars: ✭ 23 (-77.45%)
Mutual labels:  eloquent, filter
Vuejs Datatable
A Vue.js component for filterable and paginated tables.
Stars: ✭ 148 (+45.1%)
Mutual labels:  sorting, filtering
Vue Table Dynamic
🎉 A dynamic table with sorting, filtering, editing, pagination, multiple select, etc.
Stars: ✭ 106 (+3.92%)
Mutual labels:  sorting, filtering
Vue Bootstrap4 Table
Advanced table based on Vue 2 and Bootstrap 4 ⚡️
Stars: ✭ 187 (+83.33%)
Mutual labels:  sorting, filtering
Filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL.
Stars: ✭ 83 (-18.63%)
Mutual labels:  sorting, filter
Tablefilter
A Javascript library making HTML tables filterable and a bit more :)
Stars: ✭ 248 (+143.14%)
Mutual labels:  sorting, filter
ar-search
Provides unified search model for Yii ActiveRecord
Stars: ✭ 31 (-69.61%)
Mutual labels:  filter, filtering
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (-52.94%)
Mutual labels:  sorting, filtering
Depressurizer
A Steam library categorizing tool.
Stars: ✭ 1,008 (+888.24%)
Mutual labels:  sorting, filter
Feedly Filtering And Sorting
Enhance the feedly website with advanced filtering and sorting capabilities
Stars: ✭ 73 (-28.43%)
Mutual labels:  sorting, filtering

Pimp your API! Pimp your models!

Does your API need to allow filtering results? Of course it does!

Do you need to sort the results or return selected relations together with your model? I bet you do!

Let's do this!

Pimp your model!

class Post extends Eloquent {
    use PimpableTrait;
}

Pimp your API!

class PostsController extends Controller {
    public function index() {
        return Post::pimp()->get();
    }
}

What data do you need?

I need all the posts in a thread with ID 42...

...that contain a string "awesome"...

...that are no older than March 2014...

...that have been posted by any user other than the one with ID 666.

One more thing... sort it so that I get active posts at the top...

Oh, and make active and inactive posts sorted by the date they were posted...

Did I mention I need the user data with every post?

Ready... Steady... Go!

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

BAM! Done! How cool is that!

Overview

Laravel 4/5/6 package that allows to dynamically filter, sort and eager load relations for your models using request parameters.

It combines the following packages:

It simplifies embedding them in your models and allows using all 3 of them with a single function call.

Composer install

Add the following line to composer.json file in your project:

"jedrzej/pimpable": "0.0.6"

or run the following in the commandline in your project's root folder:

composer require "jedrzej/pimpable" "0.0.6"

Usage

Pimp your model

In order to pimp your model class, you need to import PimpableTrait into your model. This will internally import all 3 behaviours.

class Model extends Eloquent {
    use PimpableTrait;
}

By default all model fields are searchable and sortable; all relations can be eagerly loaded by default as well. If you need to limit which fields can be filtered and sorted by and which relations can be loaded, see documentation of corresponding behaviour package.

Pimp your API

Once you pimp your model, additional method pimp() will be available on the model that enables the additional behaviour. All criteria will be taken from the request automatically, but if you want to override the request parameters, you can pass the desired value to the pimp() method:

//override all parameters
return Model::pimp($filters, $sort, $relations)->get();

//override sorting criteria only
return Model::pimp(null, $sort)->get();

Information how to configure the behaviours using request parameters can be found in documentation of corresponding behaviour package.

Additional configuration

If you are using sort request parameter for other purpose, you can change the name of the parameter that will be interpreted as sorting criteria by setting a $sortParameterName property in your model, e.g.:

protected $sortParameterName = 'sortBy';

If you are using with request parameter for other purpose, you can change the name of the parameter that will be interpreted as a list of relations to load by setting a $withParameterName property in your model, e.g.:

protected $withParameterName = 'relations';
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].