Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

uuid

laravel

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

use Illuminate\Support\Str;

If I do something like this: 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

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?

But how do I use these new methods?

like image 255
Kevin Pimentel Avatar asked Dec 05 '22 12:12

Kevin Pimentel


1 Answers

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

like image 108
sam Avatar answered Mar 02 '23 23:03

sam