How do i generate unique 5 digit customer number with hasid

564 Views Asked by At

Hi i want to generate unique five digit customer number containing only digits from 0....9

i'm using this package : https://github.com/ivanakimov/hashids.php

i'm able to generate id but it contains alphabet like a...z

this how i'm generating

   $id = 12;
   $hashids = new Hashids\HashIds('eabangalore');  
   return $id = $hashids->encode(1, $id, 99);    // output QBsLFJw

but i want output something like this 22345,46643,...etc

how can i do that ??

1

There are 1 best solutions below

0
On

I don't think you can actually use this package for creating really unique customer number from 100000 to 999999.

I guess something like this would be a better solution:

$idWasNotCreated = true;
while ($idWasNotCreated)
    $id = mt_rand(100000, 999999);
    if (User::where('customer_number', $id)->first()) {
        $idWasNotCreated = false;
    }
}