PHPackages                             kiritokatklian/laravel-sort-request - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kiritokatklian/laravel-sort-request

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kiritokatklian/laravel-sort-request
===================================

Sorting logic for your requests, simplified.

2.0.0(3y ago)0349MITPHPPHP ^7.4|^8.0

Since Feb 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Kurozora/laravel-sort-request)[ Packagist](https://packagist.org/packages/kiritokatklian/laravel-sort-request)[ Docs](https://github.com/kurozora/laravel-sort-request)[ Fund](https://www.paypal.com/paypalme/kiritokatklian)[ RSS](/packages/kiritokatklian-laravel-sort-request/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (4)Used By (0)

[![](.github/logo.png)](.github/logo.png)

 *Sorting logic for your requests, simplified!*

Laravel Sort Request [![PHP 7.4+](https://camo.githubusercontent.com/6f8bdf66b17787ab59cf2d31bfeb448661f5d24776d9d26eed7fa1c367535745/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850253230372e342b2d3838393262662e7376673f7374796c653d666c6174266c6f676f3d504850266c6f676f436f6c6f723d7768697465)](https://swift.org) [![Laravel](https://camo.githubusercontent.com/9cfea633db2802b9dd7d7096ceffa0e19c951a13f047f524f7cb9570cce28026/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d77686974653f7374796c653d666c6174266c6f676f3d4c61726176656c)](https://laravel.com) [![Packagist](https://camo.githubusercontent.com/1458accdc694b0b7a700c35d58e1e0924efe46812976f5ed4fb485a3b0d97794/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b697269746f6b61746b6c69616e2f6c61726176656c2d736f72742d726571756573742e7376673f6c6162656c3d267374796c653d666c6174266c6f676f3d5061636b6167697374266c6f676f436f6c6f723d776869746526636f6c6f723d433235393334)](https://packagist.org/packages/kiritokatklian/laravel-sort-request) [![License](https://camo.githubusercontent.com/59497bc4563dd468e37bbf539439e60cacf196f537f678b721a8efabf21c64ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174)](https://github.com/Anarios/return-youtube-dislike/blob/main/LICENSE)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-sort-request----)

This Laravel package makes it easier to implement sorting logic into your app.
Consider the following examples:

```
# Get the cheapest items
https://example.test/items?sort=price(asc)

# Get the items sorted by name and size
https://example.test/items?sort=name(asc),size(desc)

# Get the most popular TV Shows (custom sorting behavior)
https://example.test/tv-shows?sort=popularity(most-popular)
```

Installation
============

[](#installation)

You can download a release and manually include it in your project:

PHP VersionSort Request VersionPHP 7.3[Sort Request 1.0](../../releases/tag/1.0.1)PHP 7.4[Sort Request 2.0](../../releases/tag/2.0)PHP 8.0[Sort Request 2.0](../../releases/tag/2.0)Alternatively you can install the package via composer:

```
composer require kiritokatklian/laravel-sort-request
```

Usage
=====

[](#usage)

Basic sorting
-------------

[](#basic-sorting)

Add the `SortsViaRequest` trait to your [Laravel form request](https://laravel.com/docs/6.x/validation#form-request-validation).

```
use kiritokatklian\SortRequest\Tests\Support\Requests\FormRequest;
use kiritokatklian\SortRequest\Traits\SortsViaRequest;

class GetItemsRequest extends FormRequest
{
    use SortsViaRequest;

    /**
     * Get the rules that the request enforces.
     *
     * @return array
     */
    function rules()
    {
        return array_merge([
            // This is where your normal validation rules go
        ], $this->sortingRules());
    }

    /**
     * Returns the columns that can be sorted on.
     *
     * @return array
     */
    function getSortableColumns(): array
    {
        return [
            'id', 'stackSize', 'displayName'
        ];
    }
}
```

As shown above, you will also need to implement the `getSortableColumns` method into your form request. It should return an array of column names that can be sorted on.
So if you only wanted to allow sorting on the "name" and "price" columns, you would do:

```
function getSortableColumns(): array
{
    return ['name', 'price'];
}
```

Next, go to your controller and add the `sortViaRequest` method as follows:

```
use Illuminate\Routing\Controller;
use kiritokatklian\SortRequest\Tests\Support\Models\Item;
use kiritokatklian\SortRequest\Tests\Support\Requests\GetItemsRequest;

class ItemController extends Controller
{
    /**
     * Returns a list of all items as JSON.
     *
     * @param GetItemsRequest $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    function get(GetItemsRequest $request)
    {
        $items = Item::sortViaRequest($request)->get();

        // Do something with your models...
    }
}
```

😎 That's all. You can now sort the models with the "sort" parameter.

```
# Sort a single column
https://example.test/items?sort=price(asc)

# Sort multiple columns
https://example.test/items?sort=price(asc),name(desc),experience(asc)
```

Custom sorting
--------------

[](#custom-sorting)

This package also allows you to have custom sorting behavior:

```
# Get the worst ranking users
https://example.test/user?sort=ranking(worst)

# Get the most delicious pastries, and sort them by cheapest
https://example.test/pastries?sort=taste(most-delicious),price(cheapest)
```

Please refer the [custom sorting docs](docs/CUSTOM_SORTING.md) for a guide on how to use this.

Testing
-------

[](#testing)

```
composer test
```

Contributing
============

[](#contributing)

Please refer to the **[Contributing guide](CONTRIBUTING.md)** to learn how you can help.

Credits
=======

[](#credits)

Credits go to [kurozora](https://github.com/kurozora) for creating and maintaining the package.

Special thanks

- .. to [Spatie](https://github.com/spatie) for their [template](https://github.com/spatie/skeleton-php).
- .. to [all contributors](../../contributors) for contributing to the project.

Security
========

[](#security)

If you happen to find a security vulnerability, we would appreciate you letting us know at  and allowing us to respond before disclosing the issue publicly.

Getting in Touch
================

[](#getting-in-touch)

If you have any questions or just want to say hi, join the Kurozora [Discord](https://discord.gg/f3QFzGqsah) and drop a message on the #development channel.

License
=======

[](#license)

Laravel Sort Request is an Open Source project covered by the [MIT](LICENSE).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~582 days

Total

3

Last Release

1121d ago

Major Versions

1.0.1 → 2.0.02023-04-17

PHP version history (2 changes)1.0PHP ^7.3

2.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b39f6e928a36e5e42a38ee97960f6b1d34b18b990d314d81b784d8276d81692?d=identicon)[kiritokatklian](/maintainers/kiritokatklian)

---

Top Contributors

[![musa11971](https://avatars.githubusercontent.com/u/21341801?v=4)](https://github.com/musa11971 "musa11971 (16 commits)")[![kiritokatklian](https://avatars.githubusercontent.com/u/6556281?v=4)](https://github.com/kiritokatklian "kiritokatklian (4 commits)")

---

Tags

laravel-sort-request

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kiritokatklian-laravel-sort-request/health.svg)

```
[![Health](https://phpackages.com/badges/kiritokatklian-laravel-sort-request/health.svg)](https://phpackages.com/packages/kiritokatklian-laravel-sort-request)
```

###  Alternatives

[optimistdigital/nova-simple-repeatable

A Laravel Nova simple repeatable rows field.

74151.2k](/packages/optimistdigital-nova-simple-repeatable)[icecave/chrono

A date &amp; time library that is decoupled from the system clock.

54188.9k7](/packages/icecave-chrono)[malukenho/speaknumber

Transcreve números para extenso.

2957.9k](/packages/malukenho-speaknumber)

PHPackages © 2026

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