Strengths:
useSortable, sortable trait, and sortable column). Reduces boilerplate for implementing drag-and-drop or manual ordering in models (e.g., menus, playlists, or hierarchical data).Weaknesses:
SortableJS) is managed separately, requiring additional effort for full-stack solutions.Pros:
sortable column (e.g., position or lft/rgt for nested sets). Works out-of-the-box for simple lists.Cons:
ORDER BY) may require refactoring to adopt the package’s conventions.lft/rgt for hierarchical data (like Materialized Path), which can bloat writes during reordering.sortable column is indexed; poor indexing could degrade query performance for large datasets.lft/rgt values during nested reordering could break hierarchical integrity (e.g., orphaned nodes).spatie/laravel-activitylog + custom sorting)?lft/rgt may need optimization (e.g., database-level partitioning).PUT /items/1/sort with { position: 5 })?spatie/laravel-query-builder or custom Eloquent scopes be more maintainable?EXPLAIN ANALYZE for ORDER BY queries).use \Rutorika\Sortable\Traits\Sortable;).sortable column).ORDER BY queries with sortable() method.lft/rgt (if using hierarchical data).sortable column is indexed (e.g., ALTER TABLE items ADD INDEX sortable_index(sortable)).GIN indexes if using JSON-based sorting.6.0.x for Laravel 6).// routes/web.php
Route::put('/items/{item}/sort', [ItemController::class, 'updateSortOrder']);
// SortableJS init
Sortable.create(document.querySelector('#sortable-list'), {
animation: 150,
onEnd: function (evt) {
fetch(`/items/${evt.item.dataset.id}/sort`, {
method: 'PUT',
body: JSON.stringify({ position: evt.newIndex + 1 }),
headers: { 'Content-Type': 'application/json' }
});
}
});
POST /items/sort with array of IDs).sorted_set).ORDER BY logic and custom update queries.lft/rgt issues (e.g., negative values) require deep SQL knowledge to diagnose.// app/Listeners/LogSortableEvents.php
public function handle($event) {
\Log::info('Sortable event', [
'model' => $event->model->getTable(),
'action' => $event->action,
'data' => $event->data
]);
}
How can I help you explore Laravel packages today?