Skip to content

Commit

Permalink
fixing failed call generator uid
Browse files Browse the repository at this point in the history
  • Loading branch information
yaza-putu committed Nov 27, 2021
1 parent 31258f0 commit cf6cf41
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Traits/GenUid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand All @@ -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);
}
}

0 comments on commit cf6cf41

Please sign in to comment.