Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

UUID or ULID to Hide the Main ID

Premium
3 min read

In this lesson, we will discuss UUID and ULID and how to use them in Laravel.

UUID stands for Universally Unique Identifier, and ULID stands for Universally Unique Lexicographically sortable Identifier. These are not Laravel or PHP terms, their application is broader. It's a long sequence of digits and letters to encode a more extended identifier instead of an ID field.

Now, why would you need that?


UUID

The most typical example is when you want to show a user's profile but hide the ID from the URL. For that, you may want to use a UUID.

How to use UUIDs within Laravel? First, we must create a UUID DB column.

database/migrations/xxx_add_uuid_to_users_table.php:

Schema::table('users', function (Blueprint $table) {
$table->uuid();
});

In my opinion, you should add your UUID in addition to the primary ID, not instead of ID. It would help if...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

KS
Kiril Sokolov ✓ Link copied!

I don't want to be petty, but for ULID in the uniqueIds method shouldn't it be ulid instead of uuid? Awesome course so far, keep up the great work!

N
Nerijus ✓ Link copied!

Yes it should, changed.