在 Laravel 5.6 中有新的 UUID 方法,我该如何使用它们?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48818099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:23:51  来源:igfitidea点击:

In Laravel 5.6 there are new UUID Methods, How do I use them?

phplaraveluuid

提问by LaziTurtle

In Laravel 5.6 a couple of new UUIDmethods were added under this package

在 Laravel 5.6UUID中,这个包下添加了几个新方法

use Illuminate\Support\Str;

use Illuminate\Support\Str;

If I do something like this: dd(Str::uuid());

如果我做这样的事情: dd(Str::uuid());

I get the following output:

我得到以下输出:

DegradedUuid {#215 ▼
  #codec: StringCodec {#217 ▼
    -builder: DegradedUuidBuilder {#218 ▼
      -converter: DegradedNumberConverter {#221}
    }
  }
  #fields: array:6 [▼
    "time_low" => "fbf262eb"
    "time_mid" => "e1a3"
    "time_hi_and_version" => "43f4"
    "clock_seq_hi_and_reserved" => "b1"
    "clock_seq_low" => "2f"
    "node" => "7be1b2e7490f"
  ]
  #converter: DegradedNumberConverter {#221}
}

I've never used UUID before but I am trying to create a test email verification / confirmation authentication. I did a bit of Googling and I thought I was supposed to get a string like this: fbf262eb-e1a3-43f4-b1-2f-7be1b2e7490f

我以前从未使用过 UUID,但我正在尝试创建测试电子邮件验证/确认身份验证。我做了一些谷歌搜索,我想我应该得到一个这样的字符串:fbf262eb-e1a3-43f4-b1-2f-7be1b2e7490f

And then store it in my DB and go from there. Where am I not understanding this or going wrong with this?

然后将它存储在我的数据库中并从那里开始。我在哪里不理解这一点或哪里出了问题?

Additionally, I read through this post to try and understand what an UUID is What is a UUID?

此外,我通读了这篇文章以尝试了解什么是 UUID什么是 UUID?

But how do I use these new methods?

但是我该如何使用这些新方法呢?

回答by sam

The method returns an object, if you wish to access the value directly then cast it to a string, e.g:

该方法返回一个对象,如果您希望直接访问该值,则将其转换为字符串,例如:

$uuid = (string) Str::uuid();

https://laravel.com/docs/5.6/helpers#method-str-uuid

https://laravel.com/docs/5.6/helpers#method-str-uuid