嗨,我想生成unique
五位customer number
只包含来自0....9
的数字
我正在使用这个包:https://github.com/ivanakimov/hashids.php
我能够生成id
但它包含alphabet
就像... z
这就是我的生成方式
$id = 12;
$hashids = new Hashids\HashIds('eabangalore');
return $id = $hashids->encode(1, $id, 99); // output QBsLFJw
但我想要输出像这样的22345,46643,...等
我怎样才能做到这一点 ??
我认为您实际上不能使用此软件包来创建从100000到999999的真正唯一的客户编号。
我猜这样的事情会是一个更好的解决方案:
$idWasNotCreated = true;
while ($idWasNotCreated)
$id = mt_rand(100000, 999999);
if (User::where('customer_number', $id)->first()) {
$idWasNotCreated = false;
}
}