问题描述
我使用Vinkla\hashids\Facades\hashids
生成哈希ID并将其存储在数据库中。
我使用连接如下:
'connections' => [
\App\Model\MyModel::class => [
'salt' => \App\MyModel::class.'ac81e70581b65c8bdafc495d0083fd56','length' => 16,]
]
然后我使用特征来为我的表生成哈希ID
static function getNextHashId()
{
$data = DB::table("information_schema.TABLES")
->where("TABLE_SCHEMA",env('DB_DATABASE'))
->where("TABLE_NAME",with(new static)->getTable())
->pluck("AUTO_INCREMENT")[0];
return hashids::connection(static::class)->encode($data);
}
这是我编码播种器的方式
for($i=0; $i<MySeeder::$MAXIMUM_PROJECTS; ++$i)
{
MyModel::create(array(
'hash_id'=>MyClass::getNextHashId(),...
...
));
}
我尝试为表创建200行,但是我发现生成的哈希ID是重复的,因此无法将其存储在数据库中。
我的代码有什么问题?库是否可以创建唯一的哈希?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)