Download the PHP package bytestgear/eloquent-incrementable without Composer
On this page you can find all versions of the php package bytestgear/eloquent-incrementable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bytestgear/eloquent-incrementable
More information about bytestgear/eloquent-incrementable
Files in bytestgear/eloquent-incrementable
Package eloquent-incrementable
Short Description Define a custom auto-increment field in your Eloquent model, that is determined through PHP rather than your database engine.
License MIT
Informations about the package eloquent-incrementable
Incrementable Eloquent models
Define a custom auto-increment field in your Eloquent model, that is determined through PHP rather than your database engine.
Furthermore, by making use of increment groups, you can restart counting in-table based on other fields. Consider this example:
id | code | project_id |
---|---|---|
1 | 1 | 1 |
2 | 2 | 1 |
3 | 3 | 1 |
4 | 1 | 2 |
5 | 2 | 2 |
Imagine a bug tracking application that stores each bug in a single table, but is represented
on a per-project basis. You'll want start each project with a fresh bug count, while maintaining
a unique database id. Incrementable will enable you to automatically reset the code
counter
once a new project_id
is defined.
Table of Contents
- Installation
- Usage
- Examples
- Tests
- Changelog
- Contributing
- Credits
- License
Installation
This package can be installed through Composer:
Usage
In order to add Incrementable to your Eloquent model, you'll need to:
- Use the trait on your model(s).
- Configure the incrementable field (note: make sure its an integer column).
- Optionally, add one or more increment groups.
Add the Incrementable trait on the models you want to track:
In order to avoid collisions, Incrementable will preserve the count for a soft-deleted model. Although this will cause a gap between this and the next model, it will ensure uniqueness when the model is restored.
Examples
In this example, we have set up the following:
- A table containing a
name
andcode
field. - An Eloquent model called
App\Bug
, which uses the Incrementable trait - A property on the Bug model:
$incrementable = 'code'
We can now run this example:
Tests
The package contains integration tests. You can run them using PHPUnit.
Changelog
Refer to CHANGELOG for more information.
Contributing
Refer to CONTRIBUTING for contributing details.
Credits
- Thijs Kok
- Stephan Grootveld
- Frank Keulen
- All Contributors
License
The MIT License (MIT). Refer to the License for more information.
All versions of eloquent-incrementable with dependencies
illuminate/support Version ^10.0
illuminate/database Version ^10.0
illuminate/config Version ^10.0