ARCANEDEV/noCAPTCHA

reCAPTCHA v2 issue

KumaChenGC opened this issue · 1 comments

  • noCaptcha Version: 7.0.0
  • Laravel Version: 5.7.28
  • PHP Version: 7.2.18

Description:

Route:

Route::get('captcha', 'CaptchaController@index');
Route::post('captcha', 'CaptchaController@captcha');

View:

<!DOCTYPE html>
<html lang="jp">
<head>
	<meta charset="UTF-8">
	<title>Captcha</title>
</head>
<body>
	{{ $msg ?? '' }}
	<form action="{{ action('CaptchaController@captcha') }}" method="POST">
		@csrf
		{!! no_captcha()->display() !!}<br />
		@if ($errors->has('g-recaptcha-response'))
			{{ $errors->first('g-recaptcha-response') }}<br />
		@endif
		<button type="submit">Send</button>
    </form>
    {{-- API --}}
    {!! no_captcha()->script()->toHtml() !!}
</body>
</html>

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use View;
use Validator;
use Arcanedev\NoCaptcha\Rules\CaptchaRule;

class CaptchaController extends Controller
{
    public function index(){
        return View::make('captcha');
    }
    public function captcha(Request $request){
        $rules = [
            'g-recaptcha-response' => ['required', new CaptchaRule],
        ];
        $messages = [
            'g-recaptcha-response.required' => 'Not verified yet',
            'g-recaptcha-response.captcha'  => 'verification failed',
        ];
        $validator = Validator::make($request->all(), $rules, $messages);
        if($validator->fails()){
            return View::make('captcha')->withErrors($validator->messages());
        }else{
            return View::make('captcha')->with([
                'msg' => 'Success'
            ]);
        }
    }
}

Config:

// config/no-captcha.php
'version'=>'v2'

Steps To Reproduce:

When i enter http://localhost/public/captcha

alert:
Call to undefined function no_captcha() (View: /var/www/html/laravel/resources/views/captcha.blade.php)

I believe that no_captcha() helper doesn't exists in the v7.x

Try to select the correct branch: https://github.com/ARCANEDEV/noCAPTCHA/tree/v7.x

To fix your issue, use the Captcha facade instead of no_captcha() helper.

Example: https://github.com/ARCANEDEV/noCAPTCHA/blob/v7.x/_docs/3-Usage.md#views