有没有我可以收听的重新排序事件?

Is there any reorder event that I can listen to?

在后端,每当我的模型被修改时,无论是保存、更新还是重新排序,我都需要导出数据文件。除了重新排序(拖放功能,又名重新排序行为)之外,以下函数工作正常。任何人都可以建议一种处理重新订购的方法吗?

// after the model is saved, either created or updated.   
public function afterSave()
{
  // export data here or fire the my export event
}

嗯,似乎有 trait 正在做 soting 工作 sorting and saving

它位于此处 vendor\october\rain\src\Database\Traits\Sortable.php 它已添加到模型中以使其可排序。

/**
 * Sets the sort order of records to the specified orders. If the orders is
 * undefined, the record identifier is used.
 * @param  mixed $itemIds
 * @param  array $itemOrders
 * @return void
 */
public function setSortableOrder($itemIds, $itemOrders = null)
{
    if (!is_array($itemIds)) {
        $itemIds = [$itemIds];
    }

    if ($itemOrders === null) {
        $itemOrders = $itemIds;
    }

    if (count($itemIds) != count($itemOrders)) {
        throw new Exception('Invalid setSortableOrder call - count of itemIds do not match count of itemOrders');
    }

    foreach ($itemIds as $index => $id) {
        $order = $itemOrders[$index];
        $this->newQuery()->where($this->getKeyName(), $id)->update([$this->getSortOrderColumn() => $order]);
        // ======================================= 
        // YOUR EXPORT CODE CAN BE HERE
        // =======================================
    }
}

这个方法在 sorting happens 时被调用,所以可能只是 copy this method code in your modeloverride default behavior 把你的 export logic 写在这个方法里面,它会在每次 sorting happens

so far i guess this is the simplest logic i found.

如有疑问请评论。