companue / shared-utilities
Shared utilities, traits, and helpers for Companue service packages including ordering, timestamping, and common model behaviors
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/companue/shared-utilities
Requires
- php: ^8.1
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-12-27 17:49:50 UTC
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