【问题标题】:Problem with google captcha in laravel, problem with guzzlelaravel 中的谷歌验证码问题,guzzle 问题
【发布时间】:2020-12-13 19:07:48
【问题描述】:

嗨,我已经完成了在我的网站上安装谷歌验证码所需的所有步骤。问题是我得到了这个错误

Argument 1 passed to GuzzleHttp\Client::__construct() must be of the type array, null given, called in C:\Users\userpc\Desktop\Magang\CMS\cmsglc\vendor\anhskohbo\no-captcha\src\NoCaptcha.php on line 50 (View: C:\Users\userpc\Desktop\Magang\CMS\cmsglc\resources\views\certificate\verify_certificate.blade.php)

这是我的看法

@extends('layouts.header_and_footer')
@section('title', 'Certificate')
@section('content')



                
<div class="col-lg-12 text-center mt-5">
    <h1>Search your certificate here</h1>
    <h3>Enter your certification code or your name here</h3>
</div>

@if(session()->has('message'))
<div class="alert alert-success">
    {{ session()->get('message') }}
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
@endif

@if($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert">
    {{ implode(', ', $errors->all(':message')) }}
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
@endif

<div class="col-md-4 offset-md-4 mt-5 ">
    <div class="input-group mb-3">
        <form action={{url("verify_certificate/search")}} class="site-block-top-search" method="GET" autocomplete="off">
            @csrf
            <div class="form-inline"> 
                <input type="text" class="form-control" id="search" name="s_sertif" placeholder="Search">
                <button type="submit" class="btn btn-primary">Search</button>
            </div>

            <div class="form-group{{ $errors->has('g-recaptcha-response') ? ' has-error' : '' }}">

                <label class="col-md-4 control-label">Captcha</label>

                <div class="col-md-6">

                    {!! app('captcha')->display() !!}

                    @if ($errors->has('g-recaptcha-response'))

                        <span class="help-block">

                            <strong>{{ $errors->first('g-recaptcha-response') }}</strong>

                        </span>

                    @endif

                </div>

            </div>

        </form>
    </div>
</div>



@endsection

@section('javascript')
<script src='https://www.google.com/recaptcha/api.js'></script>
@endsection

我的控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;
use DB;
use Illuminate\Support\Facades\Route;
use App\ActivityLog;
use Symfony\Component\Console\Input\Input;
use App\CmsItemEventCertif;
use Illuminate\Support\Facades\Validator;


class VerifyCertificateController extends Controller
{
    public function display(Request $request)
    {


        // $test=CmsItemEventCertif::find(1);
        // $test2 = $test->UserSertif;
        // dd($test2);
        // $la=env('APP_URL');
        // dd($la);
        $routes =  preg_match('/([a-z]*)@([a-z]*)/i', Route::currentRouteAction(), $matches);
        $routes = $matches[0];
        $action = $matches[2];
    
            DB::beginTransaction();
            try {
    
          ActivityLog::create([
    
                'inserted_date'=>Carbon::now()->TimeZone('asia/jakarta'),
                'username'=>"-",
                'application'=>$routes,
                'creator'=>"System",
                'ip_user' => $request->ip(),
                'action' => $action,
                'description'=>"Display Search Certificate From Frontend",
                'user_agent' => $request->server('HTTP_USER_AGENT')
            ]);

    
            DB::commit();
        } catch (\Exception $ex) {
            DB::rollback();
            return response()->json(['error' => $ex->getMessage()], 500);
        }
        return view('certificate.verify_certificate');
    }

    public function search(Request $request)
    {
        //$search_stf = $request->s_sertif;
        //dd($search_stf);
       // $q = Input::get ( 's_sertif' );

       DB::beginTransaction();
       try {

       $validator = Validator::make($request->all(), [

        's_sertif' => 'required',
        'g-recaptcha-response' => 'required|captcha',
    ]);

    if ($validator->fails()) {
        $desc = 'Failed to search, field cant be empty';
        // DB::beginTransaction();
      
        return redirect('/verify_certificate')
            ->withErrors($desc)
            ->withInput();
    }


        // $sertif=CmsItemEventCertif::where('code', 'ilike', '%' . $request->get('s_sertif') . '%')
        // $sertif=CmsItemEventCertif::where('code', 'ilike', '%' . $request->get('s_sertif'))
        $sertif=DB::table('cms_item_event_certificate')
        ->join('bas_user', 'bas_user.id', '=', 'cms_item_event_certificate.user_id')
        ->join('cms_item_event', 'cms_item_event.id', '=', 'cms_item_event_certificate.event_id')
        ->where('cms_item_event_certificate.code', 'ilike', '%' . $request->get('s_sertif'))
        ->orWhere('bas_user.name', 'ilike', $request->get('s_sertif') . '%')
        // ->orWhere('bas_user.name', 'ilike', '%' . $request->get('s_sertif'))
        // ->Where('name', 'ilike', '%' . $request->get('s_sertif'))
        ->select( 'cms_item_event_certificate.created_at as created_now','cms_item_event.name as event_name', 'cms_item_event_certificate.code','bas_user.name','cms_item_event_certificate.title', 'cms_item_event_certificate.event_id', 'cms_item_event.photo')
        ->get();

        DB::commit();
    } catch (\Exception $ex) {
        DB::rollback();
        return response()->json(['error' => $ex->getMessage()], 500);
    }

    if(count($sertif)>0){

        return view('certificate.verify_certificate_result' , ['sertif' => $sertif]);

        }else{
            $descc = 'Failed to search, record not found';
            return redirect('/verify_certificate')
            ->withErrors($descc)
            ->withInput();
        }
        
    }  
    
    
}

我的路线

Route::get('/verify_certificate', 'VerifyCertificateController@display');
Route::any('/verify_certificate/search', 'VerifyCertificateController@search');

我的 config.php 与 googl 验证码相关

<?php

  

      return [
    
         .....
    
         'providers' => [
    
             .....
    
             Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class
    
         ],
    
         'aliases' => [
    
             .....
    
             'NoCaptcha' => Anhskohbo\NoCaptcha\Facades\NoCaptcha::class,
    
         ]
    
      ]

有什么问题吗?我已经完成了作曲家要求,复制和粘贴相关的别名和提供程序,以及将我的网站(顺便说一句,在 url 我输入 localhost,因为它仍在本地运行)注册到谷歌 recaptcha 并输入网站和 .env 的密钥

【问题讨论】:

标签: php laravel recaptcha


【解决方案1】:

我最终在下面使用了这个,顺便说一句,感谢您的回答,至少它让我了解了谷歌验证码表单的工作原理

https://laravel-recaptcha-docs.biscolab.com/docs/intro

【讨论】:

    【解决方案2】:

    您可以从以下 2 篇文章中获取帮助来实现 google recaptcha,而无需实现任何 laravel 包:

    here

    here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      • 2017-05-12
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 2020-06-09
      • 2022-08-24
      相关资源
      最近更新 更多