Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alya_alsiyabi's avatar

Google recaptcha

I am trying to apply google captcha in my form: This is my form:

              <form action="{{ route('users.store') }}" method="POST">
                        @csrf
                        <div style="margin-left: 400px;">
                            <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-6">
                                <div class="form-group">
                                    <strong>Name:</strong>
                                    <input type="text" name="name" class="form-control" placeholder="Name">
                                </div>
                            </div>
                            </div>
                            <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-6">
                                <div class="form-group">
                                    <strong>Email:</strong>
                                    <input type="email" name="email" class="form-control" placeholder="Email">
                                </div>
                            </div>
                            </div>
                            <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-6">
                                <div class="form-group">
                                    <strong>Recaptcha:</strong>                  
                                    {!! NoCaptcha::renderJs() !!}
                                    {!! NoCaptcha::display() !!}
                                </div>
                            </div>
                            </div>
                            <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-12 text-left">
                                <button type="submit" class="btn btn-primary">Submit</button>
                            </div>
                            </div>
                        </div>
                    </form>

This is my controller:

    public function create()
    {
        return view('users.create');

    }
    public function store(Request $request)
    {  
        $request->validate([
            'name' => 'required',
            'email' => 'required|email',
            'g-recaptcha-response' => 'required|captcha',
        ]);

        User::create($request->all());

        return "Success";
    }

This is my model:

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

This is my db:

                public function up()
                {
                    Schema::create('users', function (Blueprint $table) {
                        $table->id();
                        $table->string('name');
                        $table->string('email')->unique();
                        $table->timestamp('email_verified_at')->nullable();
                        $table->string('password');
                        $table->rememberToken();
                        $table->timestamps();
                    });
                }

                /**
                 * Reverse the migrations.
                 *
                 * @return void
                 */
                public function down()
                {
                    Schema::dropIfExists('users');
                }

I added those two lines in env with the keys provided in google recatcha :

NOCAPTCHA_SECRET=XXXXXXXOWXXXXXXXXXXXXXXXXXX NOCAPTCHA_SITEKEY=XXXXXXXXXXXXXXXXXXXXXXXXXxxx

The error when I submit the form:

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.google.com/recaptcha/api/siteverify

When I remove the word "Captcha" form validation in controller in it works but as I read it is not recommended. Additionally, what I notice that when I put dd($request), just before validation in console gives me this error: POST http://127.0.0.1:8000/users 500 (Internal Server Error)

0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It looks like you are using the NoCaptcha package to integrate Google reCAPTCHA into your form. The error you are seeing is likely due to an issue with your server's SSL certificate.

To fix this, you can try updating your server's SSL certificate. If that doesn't work, you can try disabling SSL verification in the NoCaptcha package. To do this, you can add the following line of code to your config/no-captcha.php file:

'verify_ssl' => false,

This should disable SSL verification and allow you to use the reCAPTCHA without any issues.

Please or to participate in this conversation.