Support the ongoing development of →
Eloquent Laravel
Last updated 2 years ago.

Is there any reason you need to hash the ID?


You can use laravel encrypt() method to encrypt the id and the decrypt() method to get the original id.

Last updated 2 years ago.

You could use this package:

Optimus uses prime numbers and math to obfuscate ids in routes. I've used it in the past and it works fine.

However, nowadays I prefer adding an extra uuid column to the database and using that in routes like this:

Route::get('/profile/{user:uuid}', [UsersController::class, 'show']);

projectstage liked this reply


It really depends on what you're working on. If the id is being passed in the admin panel, or rather a secure part of the codebase, then it might actually be better to leave it as is, because it makes debugging simpler. Like if an employee says that an order doesn't make sense, they can just send the IT dept. the ID from the URL and you can find it in the database/api much simpler. If it's on the base user level, then using an encryption might be safer


Sign in to participate in this thread!


Your banner here too?

Veritexx veritexx Joined 19 Jan 2020


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.