Download the PHP package creativecrafts/laravel-secure-random-number-generator without Composer
On this page you can find all versions of the php package creativecrafts/laravel-secure-random-number-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download creativecrafts/laravel-secure-random-number-generator
More information about creativecrafts/laravel-secure-random-number-generator
Files in creativecrafts/laravel-secure-random-number-generator
Package laravel-secure-random-number-generator
Short Description A handy package to generate a secure unique random number for a model
License MIT
Homepage https://github.com/creativecrafts/laravel-secure-random-number-generator
Informations about the package laravel-secure-random-number-generator
laravel-secure-random-number-generator
A handy package to generate a secure unique random number for a model.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
New Features
The Laravel Secure Random Number Generator package has been enhanced with several new methods and trait to provide more flexibility and functionality when generating secure random numbers.
New Methods
Batch Generation
Formatted Numbers
Pattern-Based Numbers
Batch Formatted Numbers
Batch Pattern-Based Numbers
Range Customization
Uniqueness Validation
Usage
Generating Multiple Random Numbers
Generating Formatted Numbers
Generating Multiple Formatted Numbers
Generating Multiple Pattern-Based Numbers
Customizing Number Range
Ensuring Uniqueness in Database
Fluent Interface
All methods can be chained for a fluent interface:
Error Handling
The batch generation methods will throw a RuntimeException if they cannot generate the requested number of unique values after a reasonable number of attempts. Make sure to handle this exception in your code:
Trait
HasSecureRandomNumber
This trait provides an easy way to automatically generate and assign secure random numbers to your Laravel Eloquent models.
Usage
Basic Usage
Add the trait to any Eloquent model where you want to automatically generate a secure random number:
By default, the trait will: -Generate a secure random number when creating a new model instance -Store the number in a column named reference_number -Use the default number range from the package configuration
Customizing the Column Name
If you want to use a different column name for storing the random number, define the $randomNumberColumn property in your model:
Database Migration
Make sure to include the appropriate column in your migration:
Manually Generating Random Numbers
You can also manually generate a random number for a model:
How It Works The trait:
- Registers a creating event listener on the model
- When a new model is being created, it checks if the random number column is empty
- If empty, it generates a secure random number that is unique within the model's table
- Assigns the generated number to the specified column
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Godspower Oduose
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-secure-random-number-generator with dependencies
spatie/laravel-package-tools Version ^1.19
illuminate/contracts Version ^12.0|^11.0|^10.0