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

Mark Scherer:
Developing CakePHP 3+ Plugins, it’s fun!
Feb 01, 2016 @ 18:08:04

Mark Scherer has a post to his site looking at developing CakePHP 3+ plugins, showing how it's much easier than it used to be with previous versions of the framework.

he days of CakePHP 2 plugins and how difficult it was to actually develop plugins are over. Back in the days (OK, I still have to do it once in a while), there was even an app required to test a plugin. Since you didn’t want to have a boilerplate app for each plugin, you usually worked in your actual app. So you had cross contamination from that messing up your tests and stuff. Really annoying.

[...] While most of the concrete examples are about plugin development for CakePHP 3, the main ideas apply to all library code you write. And if you are a developer for other frameworks, the same principles apply, only the concrete implementation might differ.

He starts with the "real story" behind his development of a plugin - a need to integrate hashid support into a CakePHP v3-based application. He uses his own library as an example (here on GitHub) and shares his thought and development process in its creation. He then shares a few helpful tips for the would-be plugin authors out there:

  • Thinking about what should be in core vs a plugin.
  • Try to follow coding and package principles.
  • Following the six package principles including common reuse, common closure and package coupling practices.
tagged: cakephp3 framework plugin example principles tips hashid

Link: http://www.dereuromark.de/2016/01/29/developing-cakephp-3-plugins-its-fun/


Trending Topics: