spatie/eloquent-sortable

Feature request: global configuration for per-model options

Closed this issue · 2 comments

Let me start off by saying thank you for this package, it's looking to be really useful in one of my projects that I'm currently rewriting in Laravel. This feature request concerns these options:

    public $sortable = [
        'order_column_name' => 'order_column',
        'sort_when_creating' => true,
    ];

Since these have to be set for each model and my previous project's colum naming does not line up with this package's defaults, I currently need to specify these options for every model, making the code slightly more verbose. To avoid this I created an intermediary trait that I use in my models:

use Spatie\EloquentSortable\SortableTrait as OriginSortableTrait;

trait SortableTrait {
    use OriginSortableTrait;
    public $sortable = ['order_column_name' => 'order'];
}

but this seems like a tacky solution. I would like to propose being able to change the default values for these options via a file in the config folder, which is publishable to the project via the standard Laravel config publishing mechanism.

We would accept a PR that implements this

We'll handle this further in #97