简体   繁体   中英

How do i generate unique 5 digit customer number with hasid

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 ??

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM