diff --git a/src/Traits/GenUid.php b/src/Traits/GenUid.php index 0f28da8..bb9c98b 100644 --- a/src/Traits/GenUid.php +++ b/src/Traits/GenUid.php @@ -13,7 +13,7 @@ protected static function boot() parent::boot(); static::creating(function ($model) { if (empty($model->{$model->getKeyName()})) { - $model->{$model->getKeyName()} = uid(); + $model->{$model->getKeyName()} = $this->uid(); } }); } @@ -37,4 +37,14 @@ public function getKeyType() { return 'string'; } + + /** + * gen uid + * @param int $limit + * @return false|string + */ + public function uid($limit = 9) + { + return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit); + } }