...
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Spatie\MediaLibrary\MediaCollections\Models\Media as BaseMedia;
class MyCustomMedia extends BaseMedia implements Sortable
{
use SortableTrait;
/**
* Define the column used for sorting
* @var array
*/
public $sortable = [
'order_column_name' => 'order_column',
'sort_when_creating' => true,
];
/**
* @return Builder
*/
public function buildSortQuery(): Builder
{
return static::query()
->where('collection_name', $this->collection_name);
}
...
}
...
use Spatie\MediaLibrary\MediaCollections\Models\Concerns\IsSorted;
use Spatie\MediaLibrary\MediaCollections\Models\Media as BaseMedia;
class MyCustomMedia extends BaseMedia
{
use IsSorted;
}