Laravel Generate 4,6,8,10 Digit Unique Random Number Example

Generate 4,6,8,10 digit unique random number in laravel. In this tutorial, you will learn how to generate 2,4,6,10,12 digit unique random number in PHP laravel.
Generate 4,6,8,10 Digit Unique Random Number in PHP Laravel
You can use the random_int() function to generate 2,4,6,10, digit unique random number in PHP Laravel.
First of all, you need to know about php random_int() function. As shown following:
rand_int() function
The PHP random_int() is inbuilt PHP function. Which is used to generate a random integer number.
Syntax
The basic syntax of random_int() function is following:
random_int ( min,max);
Parameters of random_int() function
- min:- This a first parameter of this function and it is optional. Specifies the minimum/smallest/lowest number to be returned. Default is 0
- max:- This a second parameter of this function and it is also optional. Specifies the maximum/largest/highest number to be returned.
Generate 4 digit unique random number in laravel
You can use the following example to generate 4 digit unique random number in laravel:
<?php
namespace App\Http\Controllers;
class TestController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$randomNumber = random_int(1000, 9999);
dd($randomNumber);
}
}
Generate 6 digit unique random number in laravel
You can use the following example to generate 6 digit unique random number in laravel:
<?php
namespace App\Http\Controllers;
class TestController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$randomNumber = random_int(100000, 999999);
dd($randomNumber);
}
}
Recommended Laravel Posts
Recommended:-Laravel Get Record Last Week, Month, 15 Days, Year
Recommended:-Laravel where Day, Date, Month, Year, Time, Column
Recommended:-Laravel 8 Google Autocomplete Address Tutorial
Recommended:-Laravel Try Catch
Recommended:-Laravel Eloquent whereRaw Query Example
Recommended:-How to Get Random Records in Laravel
Recommended:-Laravel InsertOrIgnore Example
Recommended:-Laravel whereIn, whereNotIn With SubQuery Example
Recommended:-Laravel Eloquent withSum() and withCount() Tutorial
Recommended:-Laravel Where Null and Where Not Null Query
Recommended:-Laravel Eloquent firstWhere() Example
Recommended:-Laravel Group by Example
Recommended:-Laravel Order by Example
Recommended:-Laravel 8 Joins Example Tutorial
Recommended:-Laravel 8 – Form Validation Example
Recommended:- Laravel 8 Ajax Post Form Data With Validation
Recommended:-Laravel 8 Flash Message Example Tutorial
Recommended:-Laravel 8 Bootstrap Auth Scaffolding Example
Recommended:-Laravel 8 Auth Scaffolding using Jetstream



