Add default sorting column to your eloquent model.
You can install the package via composer:
composer require stephenjude/default-model-sorting
use Stephenjude/DefaultModelSorting/Traits/DefaultOrderBy;
class Article extends Model
{
use DefaultOrderBy;
protected static $orderByColumn = 'title';
}
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';
}
You can publish the config file by running the vendor:publish command
php artisan vendor:publish --provider="Stephenjude\DefaultModelSorting\DefaultModelSortingServiceProvider" --tag="config"
You can change the default sorting order inside the config file:
'order_by' => 'asc',
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email hello@stephenjude.me instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.