DarkGhostHunter/Captchavel

Predefined routes that should use Captchavel?

Closed this issue · 5 comments

Thanks for this package! It's a lot easier to use than some of the others I have found.

I'm trying to disable the the Recaptcha logo that appears at the bottom of every page that doesn't require Captchavel.

Is it possible to only load Captchavel on specific routes?

Thanks!
Eric

Actually, I think I figured it out. Here's what I did in case anyone else needs help.

Step 1

Set CAPTCHAVEL_MODE to manual in config/captchavel.php

Step 2

Create a new blade file with the contents of this file:

resources/views/vendor/captchavel/script.blade.php

For example, I created this file:

resources/views/components/recaptcha-script.blade.php

Step 3

At the top of that new blade file, add this:

@php($key = env('RECAPTCHA_V3_KEY'))

Step 4

In your main layout blade file (ie. app.blade.php) add the following right before the closing </head> tag:

@stack('head-scripts')

Step 5

Now, for any page where you want the Recaptcha script to show up, just add the following to that blade file:

@push('head-scripts')
    @include('components.recaptcha-script')
@endpush

Hope that helps someone (or my future self) figure this out (again).

Thanks Eric for the tutorial. I also wanted to make load reCAPTCHA v3 into only selected routes, indeed it was the initial idea, but after testing a site, I seemed that the script performed a better detection when it was loaded globally rather than only the forms routes. When I did the latter, the score was always relatively low.

I won't advice anybody to do this unless there is technical reason since makes a lot harder to have correct scores.

BTW, there is no need create files. You can use the Manual Mode and use the middleware to only inject the script on the routes you want, or manually include recaptcha::script.

If you want to disable the reCAPTCHA logo in every page, which is handled by the reCAPTCHA script, you should hide it with CSS, and add the Terms & Privacy Policy somewhere visible in your page.

Hey @DarkGhostHunter

I seemed that the script performed a better detection when it was loaded globally rather than only the forms routes

Good point. I didn't realize that reCAPTCHA V3 worked that way.

manually include recaptcha::script.

Thanks! I'll look into how to do this. That makes more sense.

Eric

Just a follow up, I followed your advice to include the script provided in the package and it worked a treat. 😄

I'm now using this in blade files where I want the recaptcha to appear.

@push('head-scripts')
    @include('captchavel::script', ['key' => env('RECAPTCHA_V3_KEY')])
@endpush