Pixelairport's avatar

Uuid for unique strings?

I use laravel a very long time now. Everytime I build an app and dont wont to use the real id of the models I used the package from https://hashids.org/ to build a hash of the real id. Then in the url i could use the hash. But that needs a salt and is more for decrypting things... i just need an handler. Now i found that:

use Ramsey\Uuid\Uuid;

Route::get('/', function () {
    echo Uuid::uuid4()->toString();
});

Does this really give me everytime a new unique string. Even when I create 1000 mysql rows at once? I need to have every uuid unique. Even after years... there should not be a copy. is that the right way?

0 likes
1 reply
bugsysha's avatar
bugsysha
Best Answer
Level 61

Yes, it will give you unique strings even if you create 1000 rows at once. You are safe.

1 like

Please or to participate in this conversation.