|
1 | | -# Generate running number when creating new records in your table. |
| 1 | +# Laravel Running Number |
2 | 2 |
|
3 | 3 | [](https://packagist.org/packages/cleaniquecoders/laravel-running-number) |
4 | 4 | [](https://github.com/cleaniquecoders/laravel-running-number/actions?query=workflow%3Arun-tests+branch%3Amain) |
5 | 5 | [](https://github.com/cleaniquecoders/laravel-running-number/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) |
6 | 6 | [](https://packagist.org/packages/cleaniquecoders/laravel-running-number) |
7 | 7 |
|
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. |
9 | 9 |
|
10 | | -## Installation |
| 10 | +## ✨ Features |
11 | 11 |
|
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: |
13 | 25 |
|
14 | 26 | ```bash |
15 | 27 | composer require cleaniquecoders/laravel-running-number |
16 | 28 | ``` |
17 | 29 |
|
18 | | -You can publish and run the migrations with: |
| 30 | +Publish and run migrations: |
19 | 31 |
|
20 | 32 | ```bash |
21 | 33 | php artisan vendor:publish --tag="running-number-migrations" |
22 | 34 | php artisan migrate |
23 | 35 | ``` |
24 | 36 |
|
25 | | -You can publish the config file with: |
| 37 | +Optionally, publish the configuration: |
26 | 38 |
|
27 | 39 | ```bash |
28 | 40 | php artisan vendor:publish --tag="running-number-config" |
29 | 41 | ``` |
30 | 42 |
|
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. |
32 | 44 |
|
33 | | -## Usage |
| 45 | +## 🚀 Quick Start |
| 46 | + |
| 47 | +### Basic Usage |
34 | 48 |
|
35 | 49 | ```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 |
37 | 60 |
|
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 | +``` |
39 | 83 |
|
40 | | -use CleaniqueCoders\RunningNumber\Generator as RunningNumberGenerator; |
| 84 | +### Custom Formatting |
41 | 85 |
|
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 |
43 | 102 | ``` |
44 | 103 |
|
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 |
46 | 126 |
|
47 | 127 | ```bash |
48 | 128 | composer test |
49 | 129 | ``` |
50 | 130 |
|
51 | | -## Changelog |
| 131 | +See the [Testing Guide](docs/05-development/01-testing.md) for more information. |
| 132 | + |
| 133 | +## 📝 Changelog |
52 | 134 |
|
53 | 135 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
54 | 136 |
|
55 | | -## Contributing |
| 137 | +## 🤝 Contributing |
56 | 138 |
|
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. |
58 | 140 |
|
59 | | -## Security Vulnerabilities |
| 141 | +## 🔒 Security |
60 | 142 |
|
61 | 143 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
62 | 144 |
|
63 | | -## Credits |
| 145 | +## 🙏 Credits |
64 | 146 |
|
65 | 147 | - [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim) |
66 | 148 | - [All Contributors](../../contributors) |
67 | 149 |
|
68 | | -## License |
| 150 | +## 📄 License |
69 | 151 |
|
70 | 152 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments