Skip to content

stephenjude/default-model-sorting

Repository files navigation

Default Model Sorting

Latest Version on Packagist Build Status Total Downloads

Add default sorting column to your eloquent model.

Installation

You can install the package via composer:

composer require stephenjude/default-model-sorting

Basic Usage

use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class Article extends Model
{
    use DefaultOrderBy;

    protected static $orderByColumn = 'title';
}

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

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

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

'order_by' => 'asc',

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@stephenjude.me instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.