Skip to content

Commit f740dbf

Browse files
committed
Enhance package with UUID support, native PHP enums, and improved running number features
- Added UUID column to running_numbers table and migration for existing records - Migrated from Spatie enums to native PHP enums with Traitify integration - Updated running number generation to support multiple sequences and custom starting points - Improved README and CHANGELOG with detailed feature descriptions and usage examples - Updated tests to validate UUID generation and uniqueness
1 parent 4830d45 commit f740dbf

File tree

11 files changed

+332
-47
lines changed

11 files changed

+332
-47
lines changed

.claude/settings.local.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(composer require:*)",
5+
"Bash(composer update:*)",
6+
"Bash(composer test:*)"
7+
],
8+
"deny": [],
9+
"ask": []
10+
}
11+
}

.github/workflows/run-tests.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,33 @@ name: run-tests
22

33
on:
44
push:
5-
branches: [main]
6-
pull_request:
7-
branches: [main]
5+
paths:
6+
- '**.php'
7+
- '.github/workflows/run-tests.yml'
8+
- 'phpunit.xml.dist'
9+
- 'composer.json'
10+
- 'composer.lock'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
815

916
jobs:
1017
test:
1118
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 5
1220
strategy:
1321
fail-fast: true
1422
matrix:
15-
os: [ubuntu-latest, windows-latest]
16-
php: [8.1, 8.2]
17-
laravel: [10.*]
18-
stability: [prefer-lowest, prefer-stable]
23+
os: [ubuntu-latest]
24+
php: [8.2, 8.3, 8.4]
25+
laravel: [12.*, 11.*, 10.*]
26+
stability: [prefer-stable]
1927
include:
28+
- laravel: 12.*
29+
testbench: 10.*
30+
- laravel: 11.*
31+
testbench: 9.*
2032
- laravel: 10.*
2133
testbench: 8.*
2234

@@ -47,4 +59,4 @@ jobs:
4759
run: composer show -D
4860

4961
- name: Execute tests
50-
run: vendor/bin/pest
62+
run: vendor/bin/pest --ci

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,60 @@
22

33
All notable changes to `laravel-running-number` will be documented in this file.
44

5+
## v3.0.0 - Major Feature Release (Planned)
6+
7+
Version 3.0.0 represents a major advancement in the package, implementing comprehensive feature enhancements and architectural improvements.
8+
9+
### 🚀 Major Features
10+
11+
#### Traitify Integration
12+
- **Native PHP Enums Support** - Migrated from `spatie/laravel-enum` to native PHP 8.1+ enums with `cleaniquecoders/traitify`
13+
- **UUID Support** - Full UUID support via `InteractsWithUuid` trait
14+
- **Enum Methods** - Enhanced enum capabilities with `values()`, `labels()`, `options()`, `descriptions()`
15+
16+
#### Running Number Management
17+
- **Reset/Restart Functionality** - Reset running numbers or restart from custom starting points
18+
- **Date-Based Formats** - Generate numbers with configurable date components (e.g., `INV-2024-01-001`)
19+
- **Multiple Sequences** - Maintain separate sequences for the same type (branch-specific, department-specific)
20+
- **Custom Starting Numbers** - Configure custom starting numbers per type
21+
- **Range Management** - Define and enforce number ranges with overflow detection
22+
23+
#### Generation Features
24+
- **Preview Mode** - Preview next number without persisting to database
25+
- **Bulk Generation** - Efficiently generate multiple numbers in a single operation
26+
- **Threading Safety** - Improved concurrency handling for high-volume generation
27+
- **Audit Trail** - Optional generation history tracking with user attribution
28+
29+
#### Developer Experience
30+
- **Eloquent Trait** - New `HasRunningNumber` trait for seamless model integration
31+
- **Artisan Commands** - CLI commands for list, reset, restart, preview, and statistics
32+
- **Events System** - `RunningNumberGenerated` and `RunningNumberReset` events for extensibility
33+
- **Service Container Integration** - Enhanced dependency injection support
34+
35+
### 📚 Documentation
36+
- Complete documentation overhaul with structured guides
37+
- 20+ dedicated documentation files organized in progressive learning path
38+
- Comprehensive examples for common scenarios
39+
- Advanced integration patterns guide
40+
- Developer contribution guidelines
41+
42+
### ⚡ Breaking Changes
43+
44+
**Enum Migration**: Updated from Spatie enums to native PHP enums with Traitify
45+
**Database Schema**: Added required `uuid` column to `running_numbers` table
46+
**Configuration**: Extended with new options for reset periods, date formats, starting numbers, and audit trail
47+
48+
See the [Upgrade Guide](docs/06-upgrade-guide.md) for detailed migration instructions.
49+
50+
### 📦 Dependencies
51+
- Added `cleaniquecoders/traitify` for UUID and enum support
52+
- Minimum PHP 8.1+ required
53+
- Laravel 9-12 supported
54+
55+
**Full Documentation**: See [docs/06-upgrade-guide.md](docs/06-upgrade-guide.md) for complete v3.0.0 upgrade guide
56+
57+
---
58+
559
## Added Laravel 12 and PHP 8.4 Support - 2025-05-01
660

761
### What's Changed

README.md

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,152 @@
1-
# Generate running number when creating new records in your table.
1+
# Laravel Running Number
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/cleaniquecoders/laravel-running-number.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-running-number)
44
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/cleaniquecoders/laravel-running-number/run-tests?label=tests)](https://github.com/cleaniquecoders/laravel-running-number/actions?query=workflow%3Arun-tests+branch%3Amain)
55
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/cleaniquecoders/laravel-running-number/Check%20&%20fix%20styling?label=code%20style)](https://github.com/cleaniquecoders/laravel-running-number/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/cleaniquecoders/laravel-running-number.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-running-number)
77

8-
Generate running number when creating new records in your table.
8+
Generate sequential running numbers for your Laravel application. Perfect for invoice numbers, order numbers, customer IDs, and any other sequential identifiers you need.
99

10-
## Installation
10+
## ✨ Features
1111

12-
You can install the package via composer:
12+
- 🔢 **Sequential Generation** - Automatic sequential number generation per type
13+
- 💾 **Database Persistence** - Reliable state storage in your database
14+
- ⚙️ **Configurable** - Customize padding, formatting, and behavior
15+
- 🆔 **UUID Support** - Built-in UUID support for running number records
16+
- 🏷️ **Native PHP Enums** - Modern PHP 8.1+ enum support with Traitify
17+
- 🔧 **Extensible** - Custom generators and presenters via contracts
18+
- 🚀 **Developer Friendly** - Helper functions, facades, and excellent IDE support
19+
-**Well Tested** - Comprehensive test coverage
20+
- 📦 **Wide Compatibility** - Laravel 9-12 & PHP 8.1-8.4
21+
22+
## 📦 Installation
23+
24+
Install via Composer:
1325

1426
```bash
1527
composer require cleaniquecoders/laravel-running-number
1628
```
1729

18-
You can publish and run the migrations with:
30+
Publish and run migrations:
1931

2032
```bash
2133
php artisan vendor:publish --tag="running-number-migrations"
2234
php artisan migrate
2335
```
2436

25-
You can publish the config file with:
37+
Optionally, publish the configuration:
2638

2739
```bash
2840
php artisan vendor:publish --tag="running-number-config"
2941
```
3042

31-
Please make sure to configure the `config/running-number` types, in order to support your requirement.
43+
> **📖 Detailed Guide**: See the complete [Installation Guide](docs/01-getting-started/01-installation.md) for more information.
3244
33-
## Usage
45+
## 🚀 Quick Start
46+
47+
### Basic Usage
3448

3549
```php
36-
running_number()->type($type)->generate();
50+
use CleaniqueCoders\RunningNumber\Enums\Organization;
51+
52+
// Using the helper function
53+
$number = running_number()
54+
->type(Organization::PROFILE->value)
55+
->generate();
56+
// Output: PROFILE001
57+
```
58+
59+
### In Model Events
3760

38-
// OR
61+
```php
62+
use Illuminate\Database\Eloquent\Model;
63+
64+
class Invoice extends Model
65+
{
66+
protected static function booted()
67+
{
68+
static::creating(function ($invoice) {
69+
$invoice->invoice_number = running_number()
70+
->type('invoice')
71+
->generate();
72+
});
73+
}
74+
}
75+
76+
// Now every invoice automatically gets a sequential number
77+
$invoice = Invoice::create([
78+
'customer_id' => 1,
79+
'amount' => 100.00,
80+
]);
81+
// invoice_number: INVOICE001
82+
```
3983

40-
use CleaniqueCoders\RunningNumber\Generator as RunningNumberGenerator;
84+
### Custom Formatting
4185

42-
RunningNumberGenerator::make()->type($type)->generate();
86+
```php
87+
use CleaniqueCoders\RunningNumber\Contracts\Presenter;
88+
89+
class CustomPresenter implements Presenter
90+
{
91+
public function format(string $type, int $number): string
92+
{
93+
return sprintf('%s-%04d', $type, $number);
94+
}
95+
}
96+
97+
$number = running_number()
98+
->type('invoice')
99+
->formatter(new CustomPresenter())
100+
->generate();
101+
// Output: INVOICE-0001
43102
```
44103

45-
## Testing
104+
> **📖 Learn More**: Check out the [Quick Start Guide](docs/01-getting-started/02-quick-start.md) and [Common Scenarios](docs/03-usage/05-common-scenarios.md) for more examples.
105+
106+
## 📚 Documentation
107+
108+
Comprehensive documentation is available in the [docs](docs/) directory:
109+
110+
- **[Getting Started](docs/01-getting-started/)** - Installation, quick start, and core concepts
111+
- **[Configuration](docs/02-configuration/)** - Configuration options, types, enums, and models
112+
- **[Usage](docs/03-usage/)** - Helper functions, facades, model integration, and examples
113+
- **[Advanced Topics](docs/04-advanced/)** - Custom presenters, generators, and integrations
114+
- **[Development](docs/05-development/)** - Testing, contributing, and development setup
115+
116+
### Quick Links
117+
118+
- [Installation Guide](docs/01-getting-started/01-installation.md)
119+
- [Quick Start](docs/01-getting-started/02-quick-start.md)
120+
- [Common Scenarios](docs/03-usage/05-common-scenarios.md)
121+
- [Custom Presenters](docs/04-advanced/01-custom-presenters.md)
122+
- [Upgrade Guide](docs/06-upgrade-guide.md)
123+
- [API Reference](docs/README.md)
124+
125+
## 🧪 Testing
46126

47127
```bash
48128
composer test
49129
```
50130

51-
## Changelog
131+
See the [Testing Guide](docs/05-development/01-testing.md) for more information.
132+
133+
## 📝 Changelog
52134

53135
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
54136

55-
## Contributing
137+
## 🤝 Contributing
56138

57-
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
139+
We welcome contributions! Please see our [Contributing Guide](docs/05-development/02-contributing.md) for details.
58140

59-
## Security Vulnerabilities
141+
## 🔒 Security
60142

61143
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
62144

63-
## Credits
145+
## 🙏 Credits
64146

65147
- [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim)
66148
- [All Contributors](../../contributors)
67149

68-
## License
150+
## 📄 License
69151

70152
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
],
1818
"require": {
1919
"php": "^8.1 | ^8.2 | ^8.3 | ^8.4",
20+
"cleaniquecoders/traitify": "^1.2",
2021
"illuminate/contracts": "^9.0 | ^10.0 | ^11.0 | ^12.0",
21-
"spatie/laravel-enum": "^3.0",
2222
"spatie/laravel-package-tools": "^1.14"
2323
},
2424
"require-dev": {
@@ -73,4 +73,4 @@
7373
},
7474
"minimum-stability": "dev",
7575
"prefer-stable": true
76-
}
76+
}

config/running-number.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
|
1919
*/
2020

21-
'types' => [
22-
Organization::organization()->value,
23-
Organization::division()->value,
24-
Organization::section()->value,
25-
Organization::unit()->value,
26-
Organization::profile()->value,
27-
],
21+
'types' => Organization::values(),
2822

2923
'model' => \CleaniqueCoders\RunningNumber\Models\RunningNumber::class,
3024

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::table('running_numbers', function (Blueprint $table) {
12+
$table->uuid('uuid')->nullable()->unique()->after('id');
13+
});
14+
15+
// Generate UUIDs for existing records
16+
$model = config('running-number.model');
17+
$model::whereNull('uuid')->each(function ($record) {
18+
$record->uuid = (string) \Illuminate\Support\Str::uuid();
19+
$record->save();
20+
});
21+
}
22+
23+
public function down()
24+
{
25+
Schema::table('running_numbers', function (Blueprint $table) {
26+
$table->dropColumn('uuid');
27+
});
28+
}
29+
};

0 commit comments

Comments
 (0)