PHPackages                             stephenjude/default-model-sorting - 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. stephenjude/default-model-sorting

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

stephenjude/default-model-sorting
=================================

Add default sorting column to your eloquent model

4.0.0(1y ago)38115.4k↓24%6MITPHP

Since Jul 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/stephenjude/default-model-sorting)[ Packagist](https://packagist.org/packages/stephenjude/default-model-sorting)[ Docs](https://github.com/stephenjude/default-model-sorting)[ RSS](/packages/stephenjude-default-model-sorting/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

Default Model Sorting
=====================

[](#default-model-sorting)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9744215c74eac2c27f56e758ce3df1c2e951c7bf56a9f6416c49e74980225641/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374657068656e6a7564652f64656661756c742d6d6f64656c2d736f7274696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stephenjude/default-model-sorting)[![Build Status](https://camo.githubusercontent.com/357ff18af3a0510c9ac747fae370b3c4f7778a72b0ea260ca3c245278f4c6015/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7374657068656e6a7564652f64656661756c742d6d6f64656c2d736f7274696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/stephenjude/default-model-sorting)[![Total Downloads](https://camo.githubusercontent.com/3c92b8c7f459c4c19cb7ec208cd406c2fd2981e38a924e1b0867629b1935d1ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7374657068656e6a7564652f64656661756c742d6d6f64656c2d736f7274696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stephenjude/default-model-sorting)

Add default sorting column to your eloquent model.

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

[](#installation)

You can install the package via composer:

```
composer require stephenjude/default-model-sorting
```

Basic Usage
-----------

[](#basic-usage)

```
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class Article extends Model
{
    use DefaultOrderBy;

    protected static $orderByColumn = 'title';
}
```

### Column Sorting Order

[](#column-sorting-order)

You can change the default column sorting order by adding the `$orderByColumnDirection` property inside your eloquent model.

```
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class Article extends Model
{
    use DefaultOrderBy;

    protected static $orderByColumn = 'title';

    protected static $orderByColumnDirection = 'desc';
}
```

Configurations
--------------

[](#configurations)

### Publishing Config

[](#publishing-config)

You can publish the config file by running the `vendor:publish command`

```
php artisan vendor:publish --provider="Stephenjude\DefaultModelSorting\DefaultModelSortingServiceProvider" --tag="config"

```

### Configuring Default Column Sorting Order

[](#configuring-default-column-sorting-order)

You can change the default sorting order inside the config file:

```
'order_by' => 'asc',

```

### Testing

[](#testing)

```
composer test
```

### 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)

- [Stephen Jude](https://github.com/stephenjude)
- [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

45

—

FairBetter than 93% of packages

Maintenance48

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 77.5% 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 ~292 days

Recently: every ~420 days

Total

7

Last Release

389d ago

Major Versions

1.2 → 2.0.02022-02-10

2.1.0 → 3.0.02024-03-27

3.0.0 → 4.0.02025-04-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb8b712638a0d72afbc4e21574989fdfc33717a69ea3070e92104183db8068f9?d=identicon)[stephenjude](/maintainers/stephenjude)

---

Top Contributors

[![stephenjude](https://avatars.githubusercontent.com/u/31182887?v=4)](https://github.com/stephenjude "stephenjude (31 commits)")[![squatto](https://avatars.githubusercontent.com/u/748444?v=4)](https://github.com/squatto "squatto (4 commits)")[![olivermbs](https://avatars.githubusercontent.com/u/37539998?v=4)](https://github.com/olivermbs "olivermbs (2 commits)")[![AkibaWolf](https://avatars.githubusercontent.com/u/16853900?v=4)](https://github.com/AkibaWolf "AkibaWolf (1 commits)")[![Remo](https://avatars.githubusercontent.com/u/129864?v=4)](https://github.com/Remo "Remo (1 commits)")[![Zubairsoft](https://avatars.githubusercontent.com/u/91836508?v=4)](https://github.com/Zubairsoft "Zubairsoft (1 commits)")

---

Tags

eloquentlaravelmodelorderbyphpsortingmodeleloquentsortingstephenjudeorderbydefault-model-sorting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stephenjude-default-model-sorting/health.svg)

```
[![Health](https://phpackages.com/badges/stephenjude-default-model-sorting/health.svg)](https://phpackages.com/packages/stephenjude-default-model-sorting)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[prettus/l5-repository

Laravel 5|6|7|8|9|10|11|12 - Repositories to the database layer

4.2k10.8M145](/packages/prettus-l5-repository)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k22.9M268](/packages/spatie-eloquent-sortable)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)

PHPackages © 2026

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