Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ben Sampson:
Masking IDs in URLs using hashids in Laravel
May 29, 2018 @ 17:47:18

In a post to his site Ben Sampson shows how to mask IDs in URLs using hashids in a Laravel-based application. Hashids converts values into strings that can then be decoded back to their original values.

By default a URL generated by a Laravel app will contain the ID of a model like this https://app.name/users/1 where 1 is the ID of the item. Often this is absolutely fine, but sometimes you might want to hide it (or obfuscate it). The two main use cases for this I've come across so far are: Security [and it looks] More professional.

He shows how to use this package to encode and decode ID values in your URLs. He also includes updates to the models, controllers and routing to use route model binding to handle the encode/decode process. He shows how to set up different salts for different data types, setting it on each model and how to correctly bind the functionality in the main route service provider.

tagged: laravel tutorial hashid mask encode decode route model

Link: https://sampo.co.uk/blog/masking-ids-in-urls-using-hash-ids-in-laravel


Trending Topics: