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

Is there any reason you need to hash the ID?

0

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

Last updated 2 years ago.
0

You could use this package: https://github.com/cybercog/laravel-optimus

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

1

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Veritexx veritexx Joined 19 Jan 2020

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.