stephenjude/default-model-sorting

Add default sorting column to your eloquent model

3.0.0 2024-03-27 15:06 UTC

This package is auto-updated.

Last update: 2024-10-27 16:27:20 UTC


README

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.