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

janisozolins's avatar

What is the appropriate use of IDs in route URLs?

Basically I have two user models and the second one can be accessed only through the first one (they are embedded using MongoDB). I need to pass both of these IDs via URL to my controller and considering that each ID is 12 bytes long by default in MongoDB, my URLs look something like this:

http://test.dev/user/58af32ceb854d0d9e5042802/appointments/58af32ceb854d0d9e5042804

Is this a healthy approach in terms of URL readability or should I attempt stripping them down a bit and/or convert to pure integers (these ID are "glued" together using 4 different other IDs)?

0 likes
1 reply
Demers94's avatar

It's definitely not ideal in terms of readability, but if you can you might want to generate some unique slugs for your users and use those instead.

For example, if your user is named "John Doe", you could have a "john-doe" slug instead and use that instead of that long ID in the URL.

In this case I don't think it matters as much as for say a blog article, people aren't likely to copy that URL or share it or anything, but it still wouldn't hurt if you can shorten it a little bit.

Please or to participate in this conversation.