Home Blog Contact

How to generate UUID in Shopware 6?

Jan 25th 2022

Shopware 6 uses UUID as the primary key for tables. How can we generate them? That's easy:

use Shopware\Core\Framework\Uuid\Uuid;

$uuid = Uuid::randomHex();

You will get UUID's like that:

b2797f53b1b84a82a70494270f2e9b1d
ceb13f897cb342588270a0eaec046254
ff83a318808f412c9f657e9182f6ed78
ef880f9328d4497ba905fbba903a538f
6a2c6945d1714056993a42432e118b20
143ef23ebd304e4a8e002f4532d9ca44

What are UUID's

Universally unique identifier (UUID) is a random string containing the numbers 0 to 9 and the characters a to f with a length of 32.


Why Shopware 6 uses UUID's?

Good question! As everything in life there are a long list of pro's and con's. Let me point out some reasons on both sides.

Pro's

Con's

You can dive more into the UUID subject by checking some links: here, here and here.

See you on the next blogpost!