Skip to content

Commit cb25d0e

Browse files
committed
Add comprehensive documentation for Laravel Running Number
- Introduced new section on Integration Patterns with examples for event-driven integration, API integration, queue integration, caching strategies, and microservices integration. - Expanded the Advanced Topics section with detailed guides on custom presenters and generators. - Created a Testing guide with examples using Pest and PHPUnit, including best practices for testing running number generation. - Developed a Contributing guide outlining ways to contribute, reporting bugs, and submitting pull requests. - Established a Development Setup guide for setting up a local environment and running tests. - Added an Upgrade Guide detailing migration steps between major versions, including breaking changes and new features. - Enhanced the main README with structured navigation and key features of the package.
1 parent b78918d commit cb25d0e

26 files changed

+6225
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
build
66
composer.lock
77
coverage
8-
docs
98
phpunit.xml
109
phpstan.neon
1110
testbench.yaml
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Installation
2+
3+
This guide will walk you through installing and setting up Laravel Running Number in your Laravel application.
4+
5+
## Requirements
6+
7+
Before installing, ensure your environment meets these requirements:
8+
9+
- **PHP**: 8.1, 8.2, 8.3, or 8.4
10+
- **Laravel**: 9.x, 10.x, 11.x, or 12.x
11+
- **Database**: MySQL, PostgreSQL, SQLite, or SQL Server
12+
13+
## Step 1: Install via Composer
14+
15+
Install the package using Composer:
16+
17+
```bash
18+
composer require cleaniquecoders/laravel-running-number
19+
```
20+
21+
## Step 2: Publish Migrations
22+
23+
Publish the migration files to your application:
24+
25+
```bash
26+
php artisan vendor:publish --tag="running-number-migrations"
27+
```
28+
29+
This will create two migration files in your `database/migrations` directory:
30+
31+
- `create_running_number_table.php` - Creates the main running numbers table
32+
- `add_uuid_to_running_numbers_table.php` - Adds UUID support (v2.x+)
33+
34+
## Step 3: Run Migrations
35+
36+
Execute the migrations to create the required database tables:
37+
38+
```bash
39+
php artisan migrate
40+
```
41+
42+
This creates a `running_numbers` table with the following structure:
43+
44+
| Column | Type | Description |
45+
|--------|------|-------------|
46+
| `id` | bigint | Primary key |
47+
| `uuid` | uuid | Unique identifier (v2.x+) |
48+
| `type` | string | Running number type (e.g., INVOICE, PROFILE) |
49+
| `number` | integer | Current sequence number |
50+
| `created_at` | timestamp | Creation timestamp |
51+
| `updated_at` | timestamp | Last update timestamp |
52+
53+
## Step 4: Publish Configuration (Optional)
54+
55+
If you want to customize the package configuration, publish the config file:
56+
57+
```bash
58+
php artisan vendor:publish --tag="running-number-config"
59+
```
60+
61+
This creates a `config/running-number.php` file that you can customize. See the [Configuration Guide](../02-configuration/01-overview.md) for details.
62+
63+
## Verification
64+
65+
Verify the installation was successful by running a quick test in `php artisan tinker`:
66+
67+
```php
68+
php artisan tinker
69+
70+
>>> use CleaniqueCoders\RunningNumber\Enums\Organization;
71+
>>> running_number()->type(Organization::PROFILE->value)->generate();
72+
=> "PROFILE001"
73+
```
74+
75+
If you see the generated running number, you're all set! 🎉
76+
77+
## Upgrading from Previous Versions
78+
79+
If you're upgrading from a previous version, please refer to the [Upgrade Guide](../06-upgrade-guide.md) for detailed migration instructions:
80+
81+
- **[Upgrading to v3.0.0](../06-upgrade-guide.md#upgrading-to-v3x-from-v2x)** - Documentation & developer experience enhancements
82+
- **[Upgrading to v2.x](../06-upgrade-guide.md#upgrading-to-v2x-from-v1x)** - Native PHP enums, UUID support
83+
84+
## Troubleshooting
85+
86+
### Migration Already Exists
87+
88+
If you see an error that the migration already exists, you may have previously installed an older version. Check your `database/migrations` directory and remove any old running number migrations before publishing the new ones.
89+
90+
### Table Already Exists
91+
92+
If the `running_numbers` table already exists from a previous installation, you can skip the migration or modify the migration file to only add the UUID column if upgrading from v1.x.
93+
94+
### Class Not Found
95+
96+
If you encounter "Class not found" errors, make sure to:
97+
98+
1. Clear your application cache: `php artisan config:clear && php artisan cache:clear`
99+
2. Regenerate the autoload files: `composer dump-autoload`
100+
101+
## Next Steps
102+
103+
Now that you have the package installed, check out the [Quick Start Guide](02-quick-start.md) to learn how to use it!
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Quick Start
2+
3+
Get up and running with Laravel Running Number in just a few minutes! This guide covers the most common use cases.
4+
5+
## Basic Usage
6+
7+
### Using the Helper Function
8+
9+
The simplest way to generate a running number is using the `running_number()` helper function:
10+
11+
```php
12+
use CleaniqueCoders\RunningNumber\Enums\Organization;
13+
14+
$runningNumber = running_number()
15+
->type(Organization::PROFILE->value)
16+
->generate();
17+
18+
echo $runningNumber; // Output: PROFILE001
19+
```
20+
21+
### Using the Generator Class
22+
23+
You can also use the Generator class directly:
24+
25+
```php
26+
use CleaniqueCoders\RunningNumber\Generator;
27+
use CleaniqueCoders\RunningNumber\Enums\Organization;
28+
29+
$runningNumber = Generator::make()
30+
->type(Organization::ORGANIZATION->value)
31+
->generate();
32+
33+
echo $runningNumber; // Output: ORGANIZATION001
34+
```
35+
36+
### Using the Facade
37+
38+
For those who prefer facades:
39+
40+
```php
41+
use CleaniqueCoders\RunningNumber\Facades\RunningNumber;
42+
use CleaniqueCoders\RunningNumber\Enums\Organization;
43+
44+
$runningNumber = RunningNumber::type(Organization::DIVISION->value)->generate();
45+
46+
echo $runningNumber; // Output: DIVISION001
47+
```
48+
49+
## Common Scenarios
50+
51+
### Invoice Numbers
52+
53+
Generate sequential invoice numbers for your application:
54+
55+
```php
56+
use CleaniqueCoders\RunningNumber\Enums\Organization;
57+
58+
$invoiceNumber = running_number()
59+
->type('invoice')
60+
->generate();
61+
62+
// Output: INVOICE001, INVOICE002, INVOICE003, ...
63+
```
64+
65+
**Note**: Make sure to add `'invoice'` to your `config/running-number.php` types array.
66+
67+
### Order Numbers
68+
69+
Create sequential order numbers:
70+
71+
```php
72+
$orderNumber = running_number()
73+
->type('order')
74+
->generate();
75+
76+
// Output: ORDER001, ORDER002, ORDER003, ...
77+
```
78+
79+
### Receipt Numbers
80+
81+
Generate receipt numbers with lowercase formatting:
82+
83+
```php
84+
$receiptNumber = running_number()
85+
->type('receipt')
86+
->toUpperCase(false)
87+
->generate();
88+
89+
// Output: receipt001, receipt002, receipt003, ...
90+
```
91+
92+
## Working with Models
93+
94+
Integrate running numbers directly into your Eloquent models:
95+
96+
```php
97+
use Illuminate\Database\Eloquent\Model;
98+
use CleaniqueCoders\RunningNumber\Enums\Organization;
99+
100+
class Invoice extends Model
101+
{
102+
protected static function booted()
103+
{
104+
static::creating(function ($invoice) {
105+
$invoice->invoice_number = running_number()
106+
->type('invoice')
107+
->generate();
108+
});
109+
}
110+
}
111+
```
112+
113+
Now every time you create a new invoice, it automatically gets a running number:
114+
115+
```php
116+
$invoice = Invoice::create([
117+
'customer_id' => 1,
118+
'amount' => 100.00,
119+
]);
120+
121+
echo $invoice->invoice_number; // INVOICE001
122+
```
123+
124+
## Case Sensitivity
125+
126+
By default, running numbers are generated in UPPERCASE. You can change this behavior:
127+
128+
```php
129+
// Uppercase (default)
130+
$number = running_number()
131+
->type(Organization::PROFILE->value)
132+
->generate();
133+
// Output: PROFILE001
134+
135+
// Lowercase
136+
$number = running_number()
137+
->type(Organization::PROFILE->value)
138+
->toUpperCase(false)
139+
->generate();
140+
// Output: profile002
141+
```
142+
143+
## Multiple Types
144+
145+
Generate running numbers for different types independently:
146+
147+
```php
148+
// Each type maintains its own sequence
149+
$invoice = running_number()->type('invoice')->generate(); // INVOICE001
150+
$order = running_number()->type('order')->generate(); // ORDER001
151+
$invoice2 = running_number()->type('invoice')->generate(); // INVOICE002
152+
$order2 = running_number()->type('order')->generate(); // ORDER002
153+
```
154+
155+
## Viewing Generated Numbers
156+
157+
You can query the running numbers table directly to see all generated sequences:
158+
159+
```php
160+
use CleaniqueCoders\RunningNumber\Models\RunningNumber;
161+
162+
// Get all running number types
163+
$types = RunningNumber::all();
164+
165+
// Get specific type
166+
$profileNumbers = RunningNumber::where('type', 'PROFILE')->first();
167+
echo $profileNumbers->number; // Current count
168+
169+
// Access UUID
170+
echo $profileNumbers->uuid; // e.g., "550e8400-e29b-41d4-a716-446655440000"
171+
```
172+
173+
## What's Next?
174+
175+
Now that you've learned the basics, explore these topics:
176+
177+
- **[Core Concepts](03-core-concepts.md)** - Understand how the package works under the hood
178+
- **[Configuration](../02-configuration/01-overview.md)** - Customize the package to your needs
179+
- **[Usage Guide](../03-usage/01-helper-functions.md)** - Learn advanced usage patterns
180+
- **[Advanced Topics](../04-advanced/01-custom-presenters.md)** - Create custom formatters and extend functionality
181+
182+
## Quick Reference
183+
184+
```php
185+
// Basic generation
186+
running_number()->type('invoice')->generate();
187+
188+
// Lowercase
189+
running_number()->type('receipt')->toUpperCase(false)->generate();
190+
191+
// Using enum
192+
use CleaniqueCoders\RunningNumber\Enums\Organization;
193+
running_number()->type(Organization::PROFILE->value)->generate();
194+
195+
// In model events
196+
static::creating(function ($model) {
197+
$model->number = running_number()->type('type')->generate();
198+
});
199+
```

0 commit comments

Comments
 (0)