acf
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/evomark/public_html/wp-includes/functions.php on line 6121Sometimes the data that flows from the backend of your application to the frontend can reveal more than you want to.<\/p>\n\n\n\n
Image an ecommerce scenario where every time an order is completed, a record is added to the orders table. Now imagine that you want your customers to be able to view their own orders within their own frontend account area. If you use standard incrementing IDs to identify these orders, you could easily reveal to that user the amount of orders your site gets in a time period.<\/p>\n\n\n\n
The first option is to use UUIDs as your primary key on a table. This is probably the most robust method but it comes with a few downsides:<\/p>\n\n\n\n
The second option is to use a standard incrementing primary key internally, but obfuscate it whenever its sent to the frontend.<\/p>\n\n\n\n
Of course, models pass from backend to frontend and vice-versa in a myriad different ways and having to manually apply obfuscation and de-obfuscation every time would be immensely tedious and limit your use of the Laravel framework in some ways (e.g. route model binding).<\/p>\n\n\n\n
Additionally, you need a robust way to encode and decode your IDs to ensure that they always resolve to the same underlying key. You also don’t want this process to be easily implementable by an unconnected party (thus making standard encoding with base64, MD5 et al. off-limits).<\/p>\n\n\n\n
This Laravel package tackles most of those challenges. Once the trait After installing the package, simply add the supplied trait to any models you want to have the ID obfuscated on:<\/p>\n\n\n\n Laravel ID Obfuscator<\/strong> comes with a built-in rule extension for validating incoming obfuscated ids, simply:<\/p>\n\n\n\n You can access the encoding and decoding features anytime via the provided facade.<\/p>\n\n\n\n You can publish the package config by running the following Artisan command: <\/p>\n\n\n\nObfuscatable<\/code> is applied to your model, the following actions are automatically taken:<\/p>\n\n\n\n
\n
find<\/code> functions work with either the original key, or the obfuscated one<\/li>\n\n\n\n
obfuscatedId<\/code> is automatically appended to your model instance to allow you to reference it internally<\/li>\n\n\n\n
toArray<\/code> function<\/li>\n\n\n\n
Usage<\/h2>\n\n\n\n
Obfuscatable<\/code> models will also feature automatic decoding when using the model’s
find<\/code>-style functions: e.g.
find<\/code>,
findOrFail<\/code>,
findMany<\/code>,
findOrNew<\/code>,
findOr<\/code><\/p>\n\n\n\n
Validation<\/h2>\n\n\n\n
Facade<\/h2>\n\n\n\n
Config<\/h2>\n\n\n\n
Setting<\/th> Type<\/th> Default<\/th> Description<\/th><\/tr><\/thead> seed<\/td> string<\/td> laravel-id-obfuscator<\/td> A seed string for the encoder<\/td><\/tr> length<\/td> int<\/td> 8<\/td> The amount of chars to pad the output to<\/td><\/tr> alphabet<\/td> string<\/td> [a-zA-Z0-9] (as string)<\/td> The alphabet to use when encoding IDs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n FAQs<\/h2>\n\n\n