Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

UUID in Laravel: All You Need To Know

If you want to replace DB auto-increment IDs with something more sophisticated, one of the solutions is UUID. In this article, I will show you how UUID columns work in Laravel, and what are the options and tools to use them.


What is UUID and Why You Would Need It?

If we take a look at Wikipedia, this is the definition:

"A universally unique identifier (UUID) is a 128-bit label used for information in computer systems. The term globally unique identifier (GUID) is also used."

This term comes not from Laravel or PHP, it's a general concept for IT projects, to uniquely identify records.

Some UUID examples:

  • b898564a-4ce8-4114-9067-142b437075ae
  • 236d75e7-b7e2-41f4-af8f-7b9e9cf32ed9
  • b7c91937-74b2-4230-97cf-92433cc6dd9a

You would save these identifiers in the database, instead of (or in addition to) a typical ID column.

So, if you have these URLs in your project:

  • yourproject.com/posts/1
  • yourproject.com/transactions/123/edit

With UUID, they would look like this:

  • yourproject.com/posts/b898564a-4ce8-4114-9067-142b437075ae
  • yourproject.com/transactions/236d75e7-b7e2-41f4-af8f-7b9e9cf32ed9/edit

Why would you do that? A few reasons...

The full tutorial [9 mins, 1656 words] is only for Premium Members

Login Or Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses