Search code examples
phplaravelrecaptchalaravel-9

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'g-recaptcha-response' in 'where clause'


I get an error when using google reCaptcha. When installing reCaptcha there is no problem. But when I enter it into validation, an error like this occurs.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'g-recaptcha-response' in 'where clause'

screen_login_form
screen_error
screen_login_view
screen_login_controller


my view (u_login.blade.php):

<form method="POST" action="/login/cek" class="form-container form-bg">
 @csrf
 <div>
   <h1 class="h3 font-weight-bold text-success">LOGIN</h1>
   @error('g-recaptcha-response')
   <label class="font-weight-normal mb-4 mt-1 text-danger"><small>Login gagal.</small></label>
   enderror
 </div>

 <div class="form-group mb-1">
   <input name="email" type="email" placeholder="Email" autofocus required>
 </div>
                        
 <div class="form-group">
   <input type="password" name="password" placeholder="Password" required>
 </div>

 <div class="form-group d-flex justify-content-center">
   {!! NoCaptcha::renderJs('id', false, 'recaptchaCallback') !!}
   {!! NoCaptcha::display() !!}
 </div>

 <button type="submit" name="masuk" class="btn btn-lg btn-success btn-block mb-2" name="logout">Masuk</button>
 <div class="form-footer">
   <p> Belum punya akun? <a href="/register">Daftar di sini</a></p>
 </div>
</form>

my controller (u_auth.php):

public function authenticate(Request $request)
    {   
        $credentials = $request->validate([
            'email' => 'required|email:rfc,dns',
            'password' => 'required',
            'g-recaptcha-response' => 'required|captcha'
        ]);

        // JIKA LOGIN BERHASIL
        if (Auth::attempt($credentials)) {
            $request->session()->regenerate();
            //dd($credentials);
            return redirect()->intended('')->withToastSuccess('Berhasil masuk!');
        }
        // JIKA LOGIN GAGAL
        return back()->with('toast_error', 'Login gagal!');
    }

please help me solve this problem with your best solution.


Solution

  • In Auth::attempt() we have to pass user's creadentials.

    In this case, you are passing captcha along with credentials, so you are getting error

    If you pass only credentials with out captcha in attempt method than you will not getting any error

    I hope it will work