You can use laravel encrypt()
method to encrypt the id and the decrypt()
method to get the original id.
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
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!
The Laravel portal for problem solving, knowledge sharing and community building.
The community