定制 companue/shared-utilities 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

companue/shared-utilities

最新稳定版本:1.0.0

Composer 安装命令:

composer require companue/shared-utilities

包简介

Shared utilities, traits, and helpers for Companue service packages including ordering, timestamping, and common model behaviors

README 文档

README

Shared utilities, traits, and helpers for Companue service packages.

Features

  • Orderable Trait: Easy ordering/ranking capabilities for Eloquent models
    • Handles unique constraint conflicts with two-pass approach
    • Built-in scopes for querying ordered data
    • Bulk and single-item reordering support

Installation

composer require companue/shared-utilities

Usage

Orderable Trait

Use the trait in your model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Companue\SharedUtilities\Traits\Orderable;

class Joblevel extends Model
{
    use Orderable;

    public function orderingAttr(): string
    {
        return 'priority'; // Your ordering column
    }
}

Available Methods

  • ordered() - Scope to order query results
  • orderedDesc() - Scope to reverse order
  • getOrderingValue() - Get the ordering value
  • setOrderingValue($value) - Set the ordering value
  • reorderBatch(array $items) - Bulk reorder with unique constraint handling
  • reorderSingle($id, $position) - Move single item and shift others
  • getNextOrderingValue() - Get next available position

Example

// Get ordered items
$items = Joblevel::ordered()->get();

// Reorder multiple items
Joblevel::reorderBatch([
    ['id' => 1, 'priority' => 1],
    ['id' => 2, 'priority' => 2],
    ['id' => 3, 'priority' => 3],
]);

// Move single item
Joblevel::reorderSingle(5, 2); // Move item 5 to position 2

License

MIT

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-27