{"id":21561674,"url":"https://github.com/testmonitor/eloquent-incrementable","last_synced_at":"2025-04-10T12:06:19.400Z","repository":{"id":20573315,"uuid":"89586066","full_name":"testmonitor/eloquent-incrementable","owner":"testmonitor","description":"Define a custom auto-increment field in your Eloquent model, that is determined through PHP rather than your database engine.","archived":false,"fork":false,"pushed_at":"2025-04-09T11:28:22.000Z","size":78,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T12:28:34.071Z","etag":null,"topics":["count","eloquent","increment","laravel","model"],"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/testmonitor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-27T10:32:05.000Z","updated_at":"2025-04-09T11:25:14.000Z","dependencies_parsed_at":"2025-04-09T12:34:02.011Z","dependency_job_id":null,"html_url":"https://github.com/testmonitor/eloquent-incrementable","commit_stats":{"total_commits":102,"total_committers":4,"mean_commits":25.5,"dds":0.4411764705882353,"last_synced_commit":"40389813ad105d5c1a63f469d0236ed3476f4d6d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testmonitor%2Feloquent-incrementable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testmonitor%2Feloquent-incrementable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testmonitor%2Feloquent-incrementable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testmonitor%2Feloquent-incrementable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testmonitor","download_url":"https://codeload.github.com/testmonitor/eloquent-incrementable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248043451,"owners_count":21038453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["count","eloquent","increment","laravel","model"],"created_at":"2024-11-24T09:27:34.345Z","updated_at":"2025-04-10T12:06:19.378Z","avatar_url":"https://github.com/testmonitor.png","language":"PHP","readme":"# Incrementable Eloquent models\n\n[![Latest Stable Version](https://poser.pugx.org/testmonitor/eloquent-incrementable/v/stable)](https://packagist.org/packages/testmonitor/eloquent-incrementable)\n[![StyleCI](https://styleci.io/repos/89586066/shield)](https://styleci.io/repos/89586066)\n[![codecov](https://codecov.io/gh/testmonitor/eloquent-incrementable/graph/badge.svg?token=DU3NSZV18O)](https://codecov.io/gh/testmonitor/eloquent-incrementable)\n[![License](https://poser.pugx.org/testmonitor/eloquent-incrementable/license)](https://packagist.org/packages/eloquent-incrementable)\n\nDefine a custom auto-increment field in your Eloquent model, that is determined through PHP\nrather than your database engine.\n\nFurthermore, by making use of increment groups, you can restart counting in-table based on\nother fields. Consider this example:\n\n| id | **code** | project_id |\n|----|:--------:|:----------:|\n| 1  | **1**    | 1          |\n| 2  | **2**    | 1          |\n| 3  | **3**    | 1          |\n| 4  | **1**    | 2          |\n| 5  | **2**    | 2          |\n\nImagine a bug tracking application that stores each bug in a single table, but is represented\non a per-project basis. You'll want start each project with a fresh bug count, while maintaining\na unique database id. Incrementable will enable you to automatically reset the `code` counter\nonce a new `project_id` is defined.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Tests](#tests)\n- [Changelog](#changelog)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Installation\n\nThis package can be installed through Composer:\n\n```sh\n$ composer require testmonitor/eloquent-incrementable\n```\n\n## Usage\n\nIn order to add Incrementable to your Eloquent model, you'll need to:\u003cbr /\u003e\n\n1. Use the trait ```TestMonitor\\Incrementable\\Traits\\Incrementable``` on your model(s).\n2. Configure the incrementable field *(note: make sure its an integer column)*.\n3. Optionally, add one or more increment groups.\n\nAdd the Incrementable trait on the models you want to track:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Database\\Eloquent\\SoftDeletes;\nuse TestMonitor\\Incrementable\\Traits\\Incrementable;\n\nclass Bug extends Model\n{\n    use Incrementable, SoftDeletes;\n\n    protected $table = 'bugs';\n\n    protected $incrementable = 'code';\n\n    // This will cause the code to reset once\n    // a new project_id is found.\n    protected $incrementableGroup = ['project_id'];\n}\n```\n\nIn order to avoid collisions, Incrementable will preserve the count for a\nsoft-deleted model. Although this will cause a gap between this and the\nnext model, it will ensure uniqueness when the model is restored.\n\n## Examples\n\nIn this example, we have set up the following:\n\n- A table containing a `name` and `code` field.\n- An Eloquent model called `App\\Bug`, which uses the Incrementable trait\n- A property on the Bug model: `$incrementable = 'code'`\n\nWe can now run this example:\n\n```php\n$bug = new App\\Bug(['name' =\u003e 'It doesn\\'t work.']);\n$bug-\u003esave();\n\n// Will show '1'\necho $bug-\u003ecode;\n\n$bug = new App\\Bug(['name' =\u003e 'It really doesn\\'t work.']);\n$bug-\u003esave();\n\n// Will show '2'\necho $bug-\u003ecode;\n```\n\n## Tests\n\nThe package contains integration tests. You can run them using PHPUnit.\n\n```\n$ vendor/bin/phpunit\n```\n\n## Changelog\n\nRefer to [CHANGELOG](CHANGELOG.md) for more information.\n\n## Contributing\n\nRefer to [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\n## Credits\n\n- [Thijs Kok](https://www.testmonitor.com/)\n- [Stephan Grootveld](https://www.testmonitor.com/)\n- [Frank Keulen](https://www.testmonitor.com/)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Refer to the [License](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestmonitor%2Feloquent-incrementable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestmonitor%2Feloquent-incrementable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestmonitor%2Feloquent-incrementable/lists"}