EOT; }); Blade::directive('captchaScripts', function () { return << document.addEventListener('DOMContentLoaded', function() { window.setTimeout(function() { const captchaList = document.querySelectorAll('input[name="captcha"]'); captchaList.forEach(function(captcha) { if(captcha.value === '') { captcha.value = '$this->captchaKey'; } }); }, $this->timeThreshold); }); EOT; }); Validator::extend('required_captcha', function ($attribute, $value, $parameters, $validator) { return $value === $this->captchaKey; }, 'The form captcha failed to validate. Please try again.'); } }