{"id":35033279,"url":"https://github.com/gowelle/sku-generator","last_synced_at":"2026-05-21T06:38:45.766Z","repository":{"id":292462431,"uuid":"980926569","full_name":"gowelle/sku-generator","owner":"gowelle","description":"Laravel package for generating unique product and variant SKUs","archived":false,"fork":false,"pushed_at":"2025-11-23T17:07:35.000Z","size":168,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T22:53:07.522Z","etag":null,"topics":["ecommerce","laravel","product","sku","variant"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gowelle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-10T01:04:05.000Z","updated_at":"2025-11-28T11:13:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"12a035e5-6ea7-4dbe-8a1d-4c940a503f62","html_url":"https://github.com/gowelle/sku-generator","commit_stats":null,"previous_names":["gowelle/sku-generator"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/gowelle/sku-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowelle%2Fsku-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowelle%2Fsku-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowelle%2Fsku-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowelle%2Fsku-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gowelle","download_url":"https://codeload.github.com/gowelle/sku-generator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowelle%2Fsku-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33291048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecommerce","laravel","product","sku","variant"],"created_at":"2025-12-27T07:27:51.323Z","updated_at":"2026-05-21T06:38:45.761Z","avatar_url":"https://github.com/gowelle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel SKU Generator\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/gowelle/sku-generator.svg?style=flat-square)](https://packagist.org/packages/gowelle/sku-generator)\n[![Total Downloads](https://img.shields.io/packagist/dt/gowelle/sku-generator.svg?style=flat-square)](https://packagist.org/packages/gowelle/sku-generator)\n[![Tests](https://github.com/gowelle/sku-generator/actions/workflows/tests.yml/badge.svg)](https://github.com/gowelle/sku-generator/actions/workflows/tests.yml)\n\nGenerate meaningful SKUs for Laravel e-commerce products and variants.\n\n## Requirements\n\n- PHP ^8.3\n- Laravel ^11.0|^12.0|^13.0\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require gowelle/sku-generator\n```\n\nPublish the configuration:\n\n```bash\nphp artisan vendor:publish --tag=\"sku-generator-config\"\n```\n\n## Usage\n\nAdd the `HasSku` trait to your models:\n\n```php\nuse Gowelle\\SkuGenerator\\Concerns\\HasSku;\n\nclass Product extends Model\n{\n    use HasSku;\n}\n```\n\nSKUs will be automatically generated when models are created:\n\n```php\n$product = Product::create(['name' =\u003e 'T-Shirt']);\necho $product-\u003esku; // Output: TM-TSH-ABC12345\n\n$variant = $product-\u003evariants()-\u003ecreate([/* ... */]);\necho $variant-\u003esku; // Output: TM-TSH-ABC12345-RED-LRG\n```\n\n## Configuration\n\n```php\nreturn [\n    'prefix' =\u003e 'TM',\n    'ulid_length' =\u003e 8,\n    'separator' =\u003e '-',\n\n    'models' =\u003e [\n        \\App\\Models\\Product::class =\u003e 'product',\n        \\App\\Models\\ProductVariant::class =\u003e 'variant',\n    ],\n\n    'category' =\u003e [\n        'accessor' =\u003e 'category',\n        'field' =\u003e 'name',\n        'length' =\u003e 3,\n        'has_many' =\u003e false,\n    ],\n];\n```\n\n## SKU Format\n\n### Products\n\n- Format: `{prefix}-{category}-{unique}`\n- Example: `TM-TSH-ABC12345`\n\n### Variants\n\n- Format: `{prefix}-{category}-{unique}-{properties}`\n- Example: `TM-TSH-ABC12345-RED-LRG`\n\n## Regenerating SKUs\n\nUse the artisan command to regenerate SKUs:\n\n```bash\n# Interactive mode\nphp artisan sku:regenerate\n\n# Direct model specification\nphp artisan sku:regenerate \"App\\Models\\Product\"\n\n# Skip confirmation\nphp artisan sku:regenerate --force\n```\n\nFeatures:\n\n- Interactive model selection\n- Progress reporting\n- Chunked processing\n- Failure logging\n- Unique constraint preservation\n\n## SKU History \u0026 Audit Trail\n\nThe package includes a comprehensive audit trail system to track all SKU lifecycle events.\n\n### Setup\n\nPublish and run the migration:\n\n```bash\nphp artisan vendor:publish --tag=\"sku-generator-migrations\"\nphp artisan migrate\n```\n\n#### Customizing for Non-Integer Primary Keys\n\nIf your models or users use primary key types other than integer (e.g., UUID, string), you'll need to modify the published migration before running it.\n\nAfter publishing the migration, edit the `model_id` and `user_id` columns in the migration file to match your primary key types:\n\n**For UUID primary keys:**\n\n```php\n// Change from:\n$table-\u003eunsignedBigInteger('model_id')-\u003eindex();\n$table-\u003eunsignedBigInteger('user_id')-\u003enullable();\n\n// To:\n$table-\u003euuid('model_id')-\u003eindex();\n$table-\u003euuid('user_id')-\u003enullable();\n```\n\n**For string primary keys:**\n\n```php\n// Change from:\n$table-\u003eunsignedBigInteger('model_id')-\u003eindex();\n$table-\u003eunsignedBigInteger('user_id')-\u003enullable();\n\n// To:\n$table-\u003estring('model_id')-\u003eindex();\n$table-\u003estring('user_id')-\u003enullable();\n```\n\n**For different types on model_id and user_id:**\n\n```php\n// Example: UUID for models, integer for users\n$table-\u003euuid('model_id')-\u003eindex();\n$table-\u003eunsignedBigInteger('user_id')-\u003enullable();\n```\n\nThe migration file will be published to `database/migrations/YYYY_MM_DD_HHMMSS_create_sku_histories_table.php`.\n\n### Configuration\n\nConfigure history tracking in `config/sku-generator.php`:\n\n```php\n'history' =\u003e [\n    'enabled' =\u003e env('SKU_HISTORY_ENABLED', true),\n    'track_user' =\u003e true,\n    'track_ip' =\u003e false,\n    'track_user_agent' =\u003e false,\n    'retention_days' =\u003e null, // null = keep forever\n    'table_name' =\u003e 'sku_histories',\n],\n```\n\n### Tracked Events\n\nThe following events are automatically tracked:\n\n- **Created**: When a new SKU is generated\n- **Regenerated**: When `forceRegenerateSku()` is called\n- **Modified**: When a SKU is manually modified\n- **Deleted**: When a model with a SKU is deleted\n\n### Viewing History\n\n#### Via Model Relationship\n\n```php\n// Get all history for a model\n$history = $product-\u003eskuHistory;\n\n// Get latest history entry\n$latest = $product-\u003egetLatestSkuHistory();\n\n// Get all history entries\n$allHistory = $product-\u003egetSkuHistory();\n```\n\n#### Via Artisan Command\n\n```bash\n# View history for a specific model\nphp artisan sku:history \"App\\Models\\Product\" --id=123\n\n# View history for a specific SKU\nphp artisan sku:history --sku=\"TM-TSH-ABC12345\"\n\n# View recent changes\nphp artisan sku:history --recent --days=7\n\n# Filter by event type\nphp artisan sku:history --event=regenerated --limit=100\n```\n\n### Query Interface\n\nUse the `SkuHistory` model to query history:\n\n```php\nuse Gowelle\\SkuGenerator\\Models\\SkuHistory;\n\n// Get history for a specific model\nSkuHistory::forModel($product)-\u003eget();\n\n// Find history for a specific SKU\nSkuHistory::forSku('TM-TSH-ABC12345')-\u003eget();\n\n// Filter by event type\nSkuHistory::byEventType('regenerated')-\u003eget();\n\n// Get recent changes\nSkuHistory::recentChanges(7)-\u003eget();\n\n// Filter by date range\nSkuHistory::between('2024-01-01', '2024-12-31')-\u003eget();\n\n// Filter by user\nSkuHistory::byUser($userId)-\u003eget();\n```\n\n### Events\n\nThe package dispatches Laravel events for all SKU changes:\n\n```php\nuse Gowelle\\SkuGenerator\\Events\\{SkuCreated, SkuRegenerated, SkuModified, SkuDeleted};\n\n// Listen to events in your EventServiceProvider\nEvent::listen(SkuRegenerated::class, function ($event) {\n    // $event-\u003emodel - The model that was changed\n    // $event-\u003eoldSku - The previous SKU\n    // $event-\u003enewSku - The new SKU\n    // $event-\u003ereason - Optional reason for change\n});\n```\n\n### Cleanup Old History\n\nClean up old history records:\n\n```bash\n# Cleanup based on configured retention policy\nphp artisan sku:history:cleanup\n\n# Delete records older than 365 days\nphp artisan sku:history:cleanup --days=365\n\n# Delete records before a specific date\nphp artisan sku:history:cleanup --before=\"2024-01-01\"\n\n# Preview what would be deleted\nphp artisan sku:history:cleanup --days=365 --dry-run\n\n# Skip confirmation\nphp artisan sku:history:cleanup --days=365 --force\n```\n\n### Disabling History\n\nTo disable history tracking:\n\n```php\n// In config/sku-generator.php\n'history' =\u003e [\n    'enabled' =\u003e false,\n    // ...\n],\n\n// Or via environment variable\nSKU_HISTORY_ENABLED=false\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\nFormat code:\n\n```bash\ncomposer format\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [John Gowelle](https://github.com/gowelle)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowelle%2Fsku-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgowelle%2Fsku-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowelle%2Fsku-generator/lists"}