PHPackages                             amsoell/withable-sortable - 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. [API Development](/categories/api)
4. /
5. amsoell/withable-sortable

ActiveLibrary[API Development](/categories/api)

amsoell/withable-sortable
=========================

A Laravel package to add eager loading and sorting to your API endpoints

v1.0.0(4y ago)05MITPHPPHP ^7.4|^8.0

Since Mar 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/amsoell/withable-sortable)[ Packagist](https://packagist.org/packages/amsoell/withable-sortable)[ Docs](https://github.com/amsoell/withable-sortable)[ RSS](/packages/amsoell-withable-sortable/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel withable-sortable
=========================

[](#laravel-withable-sortable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/669c1e2012d6c7fbfa0cb4ab39a8b02287a0c7176cb76a0647c38325cac69a3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d736f656c6c2f7769746861626c652d736f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amsoell/withable-sortable)[![Total Downloads](https://camo.githubusercontent.com/29c2a0910a08b7924f6fb5deebe5e87962f909fbb1d5ab944ad1609fa98fd62c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d736f656c6c2f7769746861626c652d736f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amsoell/withable-sortable)

This Laravel package enables dynamic eager loading and sorting in your API controllers.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require amsoell/withable-sortable
```

Usage
-----

[](#usage)

Add the `withable()` and `sortable()` calls on any Eloquent queries in your API controllers to automatically enable eager loading and sorting through querystring parameters. An controllerless example:

```
use Illuminate\Support\Facades\Route;

Route::get('/users', function () {
    $users = User::query()
        ->sortable()
        ->withable();

    return $users->paginate()->withQueryString();
});
```

- `/users` will return users sorted by the default (`created_at` in ascending order)
- `/users?sort=email` will return users sorted by email address
- `/users?sort=email&direction=desc` will return users sorted by email in descending order
- `/users?with=posts` will return users with a `posts` relationship eager loaded
- `/users?with[]=posts&with[]=comments` will return users with `posts` and `comments` relationships both eager loaded

If you want to specifically eager load some relationships while allowing additional eager loads via `with=`, you can specify them in your route method:

```
$users = User::query()->withable([
    'posts',
]);
```

You can also set the default sort parameters:

```
$users = User::query()->sortable([
    'updated_at',
    'asc',
]);
```

Even when setting default eager loads or sorts, they can be added to or overridden via querystring paramters.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andy Soell](https://github.com/amsoell)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1585d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/187129?v=4)[Andy Soell](/maintainers/amsoell)[@amsoell](https://github.com/amsoell)

---

Top Contributors

[![amsoell](https://avatars.githubusercontent.com/u/187129?v=4)](https://github.com/amsoell "amsoell (2 commits)")

---

Tags

laravelamsoellwithable-sortable

### Embed Badge

![Health badge](/badges/amsoell-withable-sortable/health.svg)

```
[![Health](https://phpackages.com/badges/amsoell-withable-sortable/health.svg)](https://phpackages.com/packages/amsoell-withable-sortable)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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