Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NeVeDlE's avatar

Slug vs ID

Why would i use slugs can’t i just depend on unique id, in other words what are slug usages that id can’t do

0 likes
8 replies
tykus's avatar
tykus
Best Answer
Level 104
  • Friendly, human-readable URL's
  • not exposing the actual IDs for resources in your application

Slugs add a small additional complexity since you are not generating from the auto-incrementing ID on the database - your application must generate a candidate slug, check that it is unique on the database table, and repeat if necessary.

1 like
NeVeDlE's avatar

@tykus I think I’ll just follow the crowd and use slugs, but at least now I’ve some ideas why i use it thank you!

tykus's avatar

@NeVeDlE no worries. Just consider that slugs make sense where the is a string (name, title etc) to slug; in other cases a UUID might make more sense.

1 like
Tray2's avatar

A slug is almost always nicer than just using an id

https;//mysite.com/authors/jordan-robert

//or

https://mysite.com/authors/1

Like @tykus says, somethimes it might be an security issue with using the id, in those cases a uuid migth be a better option since they are not as easy to guess. However with the right middleware and authorizations a user should not be able to view things they don't have access to by just changing the id.

1 like
test04's avatar

SLUG = SEO

ID = !SEO

YEAH, THAT'S IT !

2 likes

Please or to participate in this conversation.