UUID生成
安装:composer require webpatser/laravel-uuid
使用: dd(Uuid::generate()->string);
获取随机数字加字母
/**
* 获取随机数字加字母
* @param $len
* @param null $chars
* @return string
*/
public function getRandomString($len, $chars = null)
{
if (is_null($chars)) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
for ($i = 0, $str = '', $lc = strlen($chars) - 1; $i < $len; $i++) {
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
UUID方法二
// 安装
composer require ramsey/uuid
// 使用
use Ramsey\Uuid\Uuid;
$uuid_info = Uuid::uuid1();
$str_uuid = $uuid_info->getHex();