adiafora / laravel-postgres-naturalsort

An example of how you can use natural sort to orderBy in Eloquent ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

laravel-postgres-naturalsort

This simple package will help you add natural sorting to your Eloquent models if you use PostgreSQL.

Installation

Run:

    composer require "adiafora/laravel-postgres-naturalsort"

Run migration on the package:

    php artisan migrate

Usage

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();

License

The MIT License (MIT). Please see License File for more information.

About

An example of how you can use natural sort to orderBy in Eloquent ORM

License:MIT License


Languages

Language:PHP 100.0%