generate unique big integer for a tables column Laravel

963 views Asked by At

How would I generate in Laravel a unique biginteger for a database table column on save.

I have

------------------------------
id  | banner_id  | title
------------------------------
1   | 2348779    | some title
------------------------------
2   | 2312779    | some title2
------------------------------

where id is my primary key and banner_id random unique bigint

2

There are 2 answers

1
Alen On

You can try something like this:

$number = rand(9999, 9999999);
0
ilhan On

if you need integer:

floor(
   microtime() 
   * rand(10,100) // range may be different
   * time() 
);

or; create a numbers_table

| id |

ALTER TABLE `numbers_table` auto_increment = 10000000000;

insert a record and get last insert id! and use it for banner_id