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 resultsorderedDesc()- Scope to reverse ordergetOrderingValue()- Get the ordering valuesetOrderingValue($value)- Set the ordering valuereorderBatch(array $items)- Bulk reorder with unique constraint handlingreorderSingle($id, $position)- Move single item and shift othersgetNextOrderingValue()- 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
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-27