-1

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.

4
  • Does this answer your question? SQLSTATE[42S22]: Column not found: 1054 Unknown column - Laravel Commented Apr 11, 2022 at 0:10
  • 1
    Welcome to SO ... what is passed to Auth::attempt are the users credentials which get used in a query to find the user (except for the password field) ... the captcha is not part of the user's credentials
    – lagbox
    Commented Apr 11, 2022 at 0:16
  • 1
    thanks @lagbox , my error is gone because of your help. Commented Apr 11, 2022 at 0:23
  • @ObsidianAge unfortunately, it didn't help me. but, thanks for answering Commented Apr 11, 2022 at 0:24

1 Answer 1

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.