【发布时间】:2018-10-11 02:51:36
【问题描述】:
我有两张表,一张用于lists,另一张用于存储已创建的lists 中的history。这些lists 非常临时,可以通过多种方法删除,因此我在历史记录中添加了reason 字段。
//Lists table
Schema::create('lists', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('message');
$table->uuid('uuid');
$table->timestamps();
});
//History table
Schema::create('history', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('message');
$table->string('reason');
$table->uuid('uuid');
$table->timestamps();
});
现在两者都有一个 uuid 字段,我可以使用 Laravel 的辅助函数 $uuid = (string) Str::uuid(); 生成一个实际的字符串来存储
$list = new List;
$list->name = 'A basic fact of life';
$list->message = 'Pineapple does not belong on pizza.'
$uuid = (string) Str::uuid();
$list->uuid = $uuid;
$list->save();
现在,当我从Lists 成功删除一条记录时,我还会在历史记录中使用其数据创建一条新记录。
$list = find($id);
$destroy = List::destroy($id);
if($destroy) {
$history = new History;
$history->name = $list->name;
$history->message $list->message;
$history->uuid = $list->uuid;
$history->reason = 'some reason';
$history->save();
}
所以我的问题是,Laravel 如何知道我生成的下一个 UUID 实际上是唯一的?
所谓的重复问题链接实际上并没有说明它如何或是否知道下一个 UUID 实际上对于过去创建的 UUID 是唯一的,而是给出了一个概率。
【问题讨论】:
-
How unique is UUID?的可能重复
标签: php laravel laravel-5 uuid