In this episode, we make our reCAPTCHA implementation way more flexible by allowing options to be passed both to the directive and the middleware. The main focus is on letting you customize aspects like which action to send to Google and what threshold you want for passing the reCAPTCHA check.
We start out by updating the directive so you can specify the action (like 'submit', but this could be anything), and show how this gets passed from your Blade template all the way to Google's reCAPTCHA. We make sure this value is inserted correctly into the code and troubleshoot a bit—checking the output in the browser console to confirm it works as intended.
Next, we head over to the middleware and set it up so you can override the score threshold per individual route. This way, some routes can require stricter bot checks than others! We add a default threshold in the config file (set to 0.8), but if you pass a threshold directly into the middleware in your routes, that value will be used instead. We walk through how this works and show the logic for falling back to the global config if no specific value is set.
To wrap things up, we test everything to make sure it's working correctly, both when customizing parameters and when sticking with defaults. By the end, you've got a much more adaptable setup for reCAPTCHA in your Laravel app—just add the directive, add the middleware, configure as you see fit, and you're ready to go!