ofcold/nova-sortable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ofcold/nova-sortable

最新稳定版本:1.0.6

Composer 安装命令:

composer require ofcold/nova-sortable

包简介

A Laravel Nova tool.

README 文档

README

Adds sorting functionality to Laravel Nova's index resource

Installing

composer require ofcold/nova-sortable

Using

  • Add a sort field to your database migrations file.

Example

$table->unsignedInteger('sort_order')->nullable();
  • Trait entry
use Ofcold\NovaSortable\SortableTrait; class Entry extends Model { use SortableTrait; }
  • Specify whether the resource needs to be sorted.
class Example extends Resource { /**  * Build an "index" query for the given resource.  *  * @param \Laravel\Nova\Http\Requests\NovaRequest $request  * @param \Illuminate\Database\Eloquent\Builder $query  *  * @return \Illuminate\Database\Eloquent\Builder  */ public static function indexQuery(NovaRequest $request, $query) { $query->when(empty($request->get('orderBy')), function ($q) { $q->getQuery()->orders = []; return $q->orderBy(static::$model::orderColumnName()); }); return $query; } /**  * Prepare the resource for JSON serialization.  *  * @param \Laravel\Nova\Http\Requests\NovaRequest $request  * @param \Illuminate\Support\Collection $fields  *  * @return array  */ public function serializeForIndex(NovaRequest $request, $fields = null) { return array_merge(parent::serializeForIndex($request, $fields), [ 'sortable' => true ]); } }

Change sort field name

You only need to change the method 'orderColumnName' in your entry.

/*  * Determine the column name of the order column.  */ public static function orderColumnName(): string { return 'your sort order column name'; }

Demos

demos.gif?sanitize=true

统计信息

  • 总下载量: 236.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 1
  • Forks: 10
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固