Download the PHP package hexify/laravel-id-customizer without Composer
On this page you can find all versions of the php package hexify/laravel-id-customizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hexify/laravel-id-customizer
More information about hexify/laravel-id-customizer
Files in hexify/laravel-id-customizer
Package laravel-id-customizer
Short Description A laravel package to customize IDs formats.
License MIT
Informations about the package laravel-id-customizer
Laravel ID Customizer
A laravel package to customize IDs formats.
In many laravel applications, using standar behaviors for generating IDs is not good idea for some Models. That's why many devs like to generate application IDs as prefixed auto incremental and someone like to generate their unique ID in a custom format.
This package will help you to generate a custom primary key or any field in your table with a custom ID.
Installation :
composer require hexify/laravel-id-customizer
Usage :
You can use it in your controller or inside your model by using trait.
-
Using it in controller :
First import ID Customizer in controller
use Hexify\LaraIdCustomizer\IdCustomizer;.
Then in your method : -
Using it in model directly :
In your model :
-Implement the interfaceHexify\LaraIdCustomizer\IdFactory;
-Add the traitHexify\LaraIdCustomizer\Traits\HasIdFactory;.
Add this array below in your model to customize the uid field value.
Or private static $idFactoryConfig = []; for default configuration.
Parameters explanation :
There is two methods for generating custom IDs 'INCREMENTAL' and 'RANDOM'.
-
Incremental like :
STD-0001STD-0002USR-0003..., while reset on prefix change is falseSTD-0001STD-0002USR-0001..., while reset on prefix change is true -
Random like :
STD-4a67STD-cc32STD-19B5..., using 'ALPHA_NUMERIC' charactersSTD-9458STD-3498STD-7453..., using 'NUMERIC' charactersSTD-agKeSTD-BvtMSTD-crrQ..., using 'ALPHA' characters
Each method must have model, column, length, prefix
model : your model class, Ex : Student::class.
column: Optional, Default is Model KeyName.
length: ID length. Optional, Default is 10.
prefix: Define your prefix. It can be a year, month or any custom letters. Optional.
N.B, if the 'column' type is (int, integer, bigint or numeric) the 'prefix' must be numeric as well.
-
With the addition of the following option in 'INCREMENTAL' method
reset_on_prefix_change: Optional, default true. If you want resetcolumnvalue to 1 on prefix change then set it true. - Or with the addition of the following options in 'RANDOM' method
set: Optional, default 'ALPHA_NUMERIC'. is a set of characters used for generating random value.
extra: Optional, add extra characters tosetoption.Examples :
=> Incremental
-
Example 01: generating 'STD-0001' ID, prefix is a non numeric value so your column should be varchar type.
-
Example 02: 'YYMM00001' ID.
-
Example 03: Determine the desired column.
- Example 04: If you don't want to reset the identifier when the prefix change.
=> Random
-
Example 01: 'IMG-k9C42a' ID.
-
Example 02: 'USR-YYMM****' ID.
-
Example 03: Define a custom
set. - Example 04: Add extra characters to
set.
All versions of laravel-id-customizer with dependencies
doctrine/dbal Version ^3.3.5
illuminate/support Version ^8.0|^9.0
illuminate/database Version ^8.0|^9.0