This is a just simple example of how you can add natural sorting to your Eloquent models if you use Postgres.
adiafora/laravel-postgres-naturalsort is a Laravel package for this is a just simple example of how you can add natural sorting to your eloquent models if you use postgres..
It currently has 0 GitHub stars and 26 downloads on Packagist (latest version 1.2).
Install it with composer require adiafora/laravel-postgres-naturalsort.
Discover more Laravel packages by adiafora
or browse all Laravel packages to compare alternatives.
Last updated
This simple package will help you add natural sorting to your Eloquent models if you use PostgreSQL.
Run:
composer require "adiafora/laravel-postgres-naturalsort"
Run migration on the package:
php artisan migrate
You can add a NaturalSortTrait to any Eloquent model
Product extends Model
{
use \Adiafora\NaturalSort\NaturalSortTrait;
}
And in your client code you can write:
Product::orderByNatural('text')->get();
or reverse sorting
Product::orderByNaturalDesc('text')->get();
The MIT License (MIT). Please see License File for more information.