PHPackages                             sukohi/neatness - 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. sukohi/neatness

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

sukohi/neatness
===============

A Laravel package to automatically add sorting system for DB query and provide URLs to switch between ASC and DESC.

4.0.2(9y ago)112.2k1MITPHP

Since Apr 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SUKOHI/Neatness)[ Packagist](https://packagist.org/packages/sukohi/neatness)[ RSS](/packages/sukohi-neatness/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (27)Used By (1)

Neatness
========

[](#neatness)

A Laravel package to automatically add sorting system for DB query and provide URLs to switch between ASC and DESC.
(This is for Laravel 5+. [For Laravel 4.2](https://github.com/SUKOHI/Neatness/tree/3.0))

[Demo](http://demo-laravel52.capilano-fw.com/neatness)

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

[](#installation)

Execute composer command.

```
composer require sukohi/neatness:4.*

```

Preparation
===========

[](#preparation)

At first, set `NeatnessTrait` in your Model.

```
use Sukohi\Neatness\NeatnessTrait;

class Item extends Eloquent {

    use NeatnessTrait;

}

```

Secondary, add configuration values also in your Model.

**default:** Default key and direction. (Required)
**columns:** Keys and column names you want to sort. (Required)
**symbols:** Labels you will be able to use in your View. (Optional)
**symbols:** Symbols you will be able to use in your View. (Optional)
**appends:** Keys you want to append to URLs. (Optional)

```
protected $neatness = [
    'default' => ['sort_id', 'desc'],
    'columns' => [
        'sort_id' => 'id',
        'sort_title' => 'title',
        'sort_date' => 'created_at'
    ],
    'labels' => [
        'sort_id' => 'ID',
        'sort_title' => 'Title',
        'sort_date' => 'Date'
    ],
    'symbols' => [
        'asc' => '',
        'desc' => '',
        'default' => ''
    ],
    'appends' => ['name']
];

```

**Multiple columns:** If you want to sort by multiple columns, you can use delimiter `|` like so.

```
'columns' => [
    'id_n_title' => 'id|title'
],

```

**Query Scope:** You also can utilize `Query Scopes` instead of column name.

```
'columns' => [
    'scope_title' => 'scope::sortTitle'
],

```

in this case, you need to prepare a scope method in your model. ([About Query Scopes](https://laravel.com/docs/4.2/eloquent#query-scopes))

```
public function scopeSortTitle($query, $direction) {

    return $query->orderBy('title', $direction);

}

```

**Label:** You can use `label::` prefix to call a specific method.

```
'labels' => [
    'title' => 'label::SortTitle'
],

```

in this case, you need to prepare a method in your model.

```
public function labelSortTitle() {

    return 'Your Title'.

}

```

Usage
=====

[](#usage)

Now you can use a method called `neatness`.

(in Controller)

```
$items = Item::neatness()->get();

```

After call `neatness()`, you can access to sort data through `$neatness`.

(in View)

**key:** The key name sorting now.

```
Key: {{ $neatness->key }}

```

**column:** The column name sorting now.

```
Column: {{ $neatness->column }}

```

**direction:** The Direction sorting now. `asc` or `desc`

```
Direction: {{ $neatness->direction }}

```

**urls:** URLs to switch sort.

```
@foreach($neatness->urls as $key => $url)
    {{ $key }} => {{ $url }}
@endforeach

or

$neatness->urls->get('title');

```

**all\_urls:** All URLs to switch sort.

```
@foreach($neatness->all_urls as $key => $urls)
    @foreach($urls as $direction => $url)
        {{ $direction }} => {{ $url }}
    @endforeach
@endforeach

or

$neatness->all_urls->get('title');          // Array
$neatness->all_urls->get('title')['desc']   // URL

```

**labels:** Labels you set in your Model.

```
@foreach($neatness->labels as $key => $label)
    {{ $key }} => {{ $label }}
@endforeach

or

$neatness->labels->get('title');

```

**symbols:** Symbols plucked with sort state.

```
@foreach($neatness->symbols as $key => $symbol)
    {{ $key }} => {{ $symbol }}
@endforeach

or

$neatness->symbols->get('title');

```

**texts:** Texts mainly for link.

```
@foreach($neatness->urls as $key => $url)
    {{ $neatness->texts->get($key) }}
@endforeach

or

$neatness->texts->get('title');

```

**appends:** Array values for pagination

```
{{ $items->appends($neatness->appends)->links() }}

```

Change default column and direction
===================================

[](#change-default-column-and-direction)

By this way, you can change default column and direction.

```
Item::neatness('title', 'desc')->get();

```

Relationship
============

[](#relationship)

You can use this package with relationship using join().

(in Controller)

```
$items = Item::join('item_details', 'item_details.item_id', '=', 'items.id')
            ->neatness()
            ->paginate(5);

```

(in Model)

```
protected $neatness = [
	'default' => ['items.id', 'desc'],
	'columns' => [
		'id' => 'items.id',
		'title' => 'items.title',
		'date' => 'items.created_at',
		'address' => 'item_details.address'
	]
];

```

License
=======

[](#license)

This package is licensed under the MIT License.

Copyright 2016 Sukohi Kuhoh

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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

Every ~6 days

Recently: every ~30 days

Total

26

Last Release

3526d ago

Major Versions

1.0.7 → 2.0.42016-04-15

1.0.8 → 2.0.52016-04-15

1.0.x-dev → 3.0.02016-04-17

3.0.0 → 4.0.02016-04-17

3.0.x-dev → 4.0.12016-07-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/2980d59b309d45df3f2e6e51b1d336614da063240b8f76f873f287cd745ec5db?d=identicon)[Sukohi](/maintainers/Sukohi)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/sukohi-neatness/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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