Download the PHP package enea/laravel-sequenceable without Composer
On this page you can find all versions of the php package enea/laravel-sequenceable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enea/laravel-sequenceable
More information about enea/laravel-sequenceable
Files in enea/laravel-sequenceable
Package laravel-sequenceable
Short Description Facilitates the generation and autocompletion of a sequential value in the database
License MIT
Informations about the package laravel-sequenceable
Laravel Sequenceable Package
Laravel Sequenceable is a library to generate and manage sequences for laravel models.
Installation
Laravel Sequenceable requires PHP 8.1.
To get the latest version, simply require the project using Composer:
Once installed, if you are not using automatic package discovery, then you need to register the Enea\Sequenceable\SequenceableServiceProvider
service provider in your config/app.php
.
Now. Publish the configuration file.
And finally run migrations.
Basic Usage
Getting started with the library is as simple as using the Sequenceable
trait and implementing the SequenceableContract
interface, after that you only need to specify the sequences you want to generate.
Advanced
We exemplify all the options to generate a sequence
with the case of a payment document.
-
To start, we need a column to store the sequence, and for this we will use a column called
number
. -
Now that we have the column defined, we realize that we need to create a separate sequence for each type of document. For this problem, the library offers the possibility of adding an scope for the column.
-
Everything is fine, but now we want the sequences not to be saved in a numeric value, but instead to be a text string with a fixed length of 10.
-
Concluding, we could also say that we do not want to use the default table for sequences and we need a special table to store the payment sequences, for this you have to create your own sequence table.
We can wrap a block of sequences using the class
Enea\Sequenceable\Wrap::create
List
To retrieve all the sequences of a model, you can use the Enea\Sequenceable\Facades\Succession
facade which is linked to the Enea\Sequenceable\Succession
class.
This returns an instance of Enea\Sequenceable\SequenceCollection
. With which you can do things like:
Config
You can change the default sequence model of config\sequenceable.php
in the model
key.
Or explicitly specify the model you want to use with certain fields, you can achieve this from the configuration of the sequences in your model.
Customize
if you already have a model to store your sequences, you need to implement the Enea\Sequenceable\Contracts\SequenceContract
interface, or extend the default model Enea\Sequenceable\Model\Sequence
.
In case you have your own sequence model, there are some fields that you should store in its sequence table:
- The column ID, and this is obtained by concatenating the column name and scope.
- The name of the table to which the sequence belongs.
- An integer type sequence.
Example
To better exemplify this, we will use the default Sequence
model.
This model comes with a default configuration.
id | sequence | source | column_id | created_at | updated_at |
---|---|---|---|---|---|
e4910d63 | 1 | documents | document_number.invoce | 2020-07-03 18:40:44 | 2020-07-03 18:40:44 |
Migration
The table structure has the required fields, you can see the migration in CreateSequencesTable
Column | Description | Required |
---|---|---|
id | It is generated on the basis of the union of the table, column and scope | :x: |
sequence | Stores the last value in the sequence | :white_check_mark: |
source | Stores the table name | :white_check_mark: |
column_id | Concatenated name and scope | :white_check_mark: |
created_at | Indicates the date and time the sequence was created | :x: |
updated_at | Indicates the last time the sequence is updated | :x: |
You can see another example of this in the test
folder and look for the files CustomSequence.php
and migrations/2017_04_23_200525_create_custom_sequences_table.php
More documentation
You can find a lot of comments within the source code as well as the tests located in the tests
directory.
All versions of laravel-sequenceable with dependencies
laravel/framework Version ^10.21|^v11.15
vaened/php-sequence-generator Version ^2.0.0