DEV Community

Discussion on: Eloquent UUIDs.

Collapse
 
bahdcoder profile image
Kati Frantz

Hey, thanks a lot for your reply @jakebman . What's your suggestion for substituting randomness with uniqueness ?

Collapse
 
jakebman profile image
jakebman

My apologies, that is a valid uuid4 method. I implied that it wasn't a valid UUID generator, and I was wrong on that point.

I'd still recommend not writing it yourself, and using a tested library implementation, which would provide other variants of UUID like 1, 3, or 5 that have the uniqueness guarantee and are harder to write yourself.

They also make it easier to follow the recommendations in this thread about not using the string representation of a UUID, which takes up more than twice the space in your database.

Collapse
 
aabdyli profile image
Albi Abdyli • Edited
//change 
$table->incrementing('id');
//to
$table->uuid('id');

laravel.com/docs/5.6/migrations#cr...

Collapse
 
aleksikauppila profile image
Aleksi Kauppila

You should check this library out: github.com/ramsey/uuid. It's very popular.

Thread Thread
 
aabdyli profile image
Albi Abdyli

That package is required by default by Laravel Framework so it is already present.