almirhodzic/nova-sortable-5
A Laravel Nova 5 package that adds drag-and-drop sorting to resource index tables. Reorder rows directly in Nova, persist positions through a configurable sort column, and keep listings organized with minimal setup. Ideal for menus, categories, FAQs, and other ordered content.
Resource::indexQuery() contract. Projects still on Nova 4 should pin the last pre-1.0.4 release rather than mixing versions.fields() method:use Vendor\NovaSortable\Sortable;
public function fields(NovaRequest $request)
{
return [
Sortable::make('Order', 'order'),
// other fields...
];
}
indexQuery() using the contract signature:use Illuminate\Database\Eloquent\Builder;
use Laravel\Nova\Http\Requests\NovaRequest;
public static function indexQuery(NovaRequest $request, $query): Builder
{
return parent::indexQuery($request, $query)->orderBy('order');
}
fields() method, the model's order column, the Resource's indexQuery(), and the package's published FormSortable.vue if you need to customize the front-end behavior.fields(); v1.0.4 hides it on create/update forms itself. Rely on that instead of manually adding showOnCreating() / showOnUpdating(), which would reintroduce the form-binding bug.order on create (Model::max('order') + 1) and resequence after deletes. Use a model observer or a small Artisan command so gaps do not accumulate.indexQuery() ordering and the reorder write. A common pattern is ordering by (scope_id, order) and resequencing within the same scope when a row moves.updateQuietly() / saveQuietly() or a direct query builder update, otherwise model observers that assign order values can fire recursively.FormSortable.vue, use the Options API and Nova's DependentFormField mixin. Do not use <script setup>; Nova expects the component to expose fill() on the field data object.update ability. Verify the package's route middleware and field-level canSee/canUpdate behavior before exposing reordering to non-admin users.indexQuery() ordering and the field's visibility rules.t.fill is not a function on form submit. This was the pre-1.0.4 failure mode caused by <script setup> not exposing the fill() method Nova binds through DependentFormField. v1.0.4 fixes it by switching to the Options API. If you published the Vue component, re-publish or diff it after upgrading; stale published views or compiled assets will keep the old behavior. Rebuild assets and clear caches.indexQuery signature drift. Any Resource override must use the Nova 5 signature with the Builder type-hint and return type. Copying an older signature causes type errors on the index endpoint.public static function indexQuery(NovaRequest $request, $query): Builder
order unless your update strategy updates rows in a collision-safe order (for example, temporary negative values before resequencing).NULL ordering differently. Backfill before enabling the field; keep the column non-nullable once migration is complete.php artisan optimize:clear, republish any package views/assets, and rebuild Nova custom assets. Browser console errors often come from old compiled JavaScript rather than PHP.storage/logs/laravel.log, and confirm the resource policy allows updates. If the order saves but the index does not reflect it, check indexQuery() ordering and any global scopes on the model.DependentFormField mixin pattern for any Nova form-field interoperability. Keep customizations in a local component rather than editing vendor files so future releases remain upgradeable.How can I help you explore Laravel packages today?