PHPackages                             jedrzej/pimpable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jedrzej/pimpable

ActiveLibrary[Database &amp; ORM](/categories/database)

jedrzej/pimpable
================

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

0.0.6(6y ago)105188.2k↓64.2%7[1 issues](https://github.com/jedrzej/pimpable/issues)1MITPHP

Since Aug 21Pushed 6y ago2 watchersCompare

[ Source](https://github.com/jedrzej/pimpable)[ Packagist](https://packagist.org/packages/jedrzej/pimpable)[ Docs](https://github.com/jedrzej/pimpable)[ RSS](/packages/jedrzej-pimpable/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (7)Used By (1)

Pimp your API! Pimp your models!
================================

[](#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
--------

[](#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:

- [Searchable](https://github.com/jedrzej/searchable) - filter models
- [Sortable](https://github.com/jedrzej/sortable) - sort models
- [Withable](https://github.com/jedrzej/withable) - eager load relations

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

Composer install
----------------

[](#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
-----

[](#usage)

### Pimp your model

[](#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

[](#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

[](#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';
```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~295 days

Recently: every ~369 days

Total

6

Last Release

2494d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/291904?v=4)[Jędrzej Kuryło](/maintainers/jedrzej)[@jedrzej](https://github.com/jedrzej)

---

Top Contributors

[![jedrzej](https://avatars.githubusercontent.com/u/291904?v=4)](https://github.com/jedrzej "jedrzej (11 commits)")[![jedrzej-x-team-com](https://avatars.githubusercontent.com/u/120025182?v=4)](https://github.com/jedrzej-x-team-com "jedrzej-x-team-com (2 commits)")[![lloy0076](https://avatars.githubusercontent.com/u/1174532?v=4)](https://github.com/lloy0076 "lloy0076 (1 commits)")[![pablomaurer](https://avatars.githubusercontent.com/u/2413156?v=4)](https://github.com/pablomaurer "pablomaurer (1 commits)")

---

Tags

eager-loadingeloquentfilterfilteringlaravelphpsearchsearchingsortingrequestapisearchlaravelmodeleloquentfiltersortablesortsearchableloadeager

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/jedrzej-pimpable/health.svg)

```
[![Health](https://phpackages.com/badges/jedrzej-pimpable/health.svg)](https://phpackages.com/packages/jedrzej-pimpable)
```

###  Alternatives

[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127270.5k5](/packages/jedrzej-searchable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k5.1M34](/packages/tucker-eric-eloquentfilter)[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k25.7M319](/packages/spatie-eloquent-sortable)[jedrzej/sortable

Sortable trait for Laravel's Eloquent models - sort your models using request parameters

54279.0k1](/packages/jedrzej-sortable)[jedrzej/withable

Withable trait for Laravel's Eloquent models

25203.4k2](/packages/jedrzej-withable)[lemaur/eloquent-publishing

218.1k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
