This package generates code in relation to year, date and month. For instance, it uses A - Z letters for months. For example 1E1NKJDQVW code 1 rep number of years, E rep month and 1 rep date while NKJDQVW is a random string. This library mimics the mpesa-transaction-id.
The recommended way to install shift-code-generator is through Composer.
# Install package via composer
composer require shiftechafrica/shift-code-generator
Next, run the Composer command to install the latest stable version of shiftechafrica/shift-code-generator:
# Update package via composer
composer update shiftechafrica/shift-code-generator --lock
After installing, the package will be auto discovered, But if need you may run:
# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload
Then run this, to get the config/shift-code-generator.php for your own configurations:
# run this to get the configuration file at config/shift-code-generator.php <-- read through it -->
php artisan vendor:publish --provider="ShiftechAfrica\CodeGenerator\ShiftCodeGeneratorServiceProvider"
A config/shift-code-generator.php file will be created, so if you want to use the database follow the next step on how to seed. The following add to your .env file.
YEAR_OF_START=2020 #pass the year that your application is launched
USE_DATABASE=false #pass true if you want to use the database and false to use your default YEAR_OF_START
You will have to add this in the database/seeds/DatabaseSeeder. To ensure we seed some data to set the default dates that will be used in generating the codes:
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
// other seeds...
$this->call(\ShiftechAfrica\CodeGenerator\Seeds\ShiftCodeGeneratorFactory::class);
}
Follow the steps below on how to use the shift-code-generator:
How to generate the code...
use ShiftechAfrica\CodeGenerator\ShiftCodeGenerator;
/**
* ----------------------------
* Generate the code here
* -----------------------------------------------------------------------
* Code will be generated in the format of Y-M-D + 7 random characters
* -----------------------------------------------------------------------
* @return string
*/
public function generateCode()
{
return (new ShiftCodeGenerator())->generate();// in the generate method you can pass an int value like 5,4 or any to get the length of the code you want
}
Version | Status | Packagist | Namespace | Repo |
---|---|---|---|---|
1.x | Latest | shiftechafrica/shift-code-generator |
ShiftechAfrica\CodeGenerator |
v1.4.7 |
For any security vulnerabilities, please email to Shiftech Africa.
This package is open-source, licensed under the MIT license.