Commit f5befe29 authored by seltix5's avatar seltix5 Committed by Nguyen Van Anh

Update for multiple app('captcha')->display() on the same page (#57)

* Update for multiple app('captcha')->display() on the same page

registerin the service provider with singleton instead of bind will return always the same object per page load. with this methos is possible to insert a control variable in the class and use it to 

* Upda for multiple noCaptcha on the same page

ading this var control will permit to request the api only once. this will work with the singleton register on te serviceprovider file.

* Update NoCaptcha.php

* Update NoCaptcha.php
parent 4fb2be48
......@@ -29,6 +29,11 @@ class NoCaptcha
*/
protected $http;
/**
* API requested control
*/
protected $api_requested = false;
/**
* NoCaptcha.
*
......@@ -53,7 +58,11 @@ class NoCaptcha
{
$attributes['data-sitekey'] = $this->sitekey;
$html = '<script src="'.$this->getJsLink($lang).'" async defer></script>'."\n";
$html = '';
if (empty($this->api_requested)) {
$this->api_requested = true;
$html .= '<script src="'.$this->getJsLink($lang).'" async defer></script>'."\n";
}
$html .= '<div class="g-recaptcha"'.$this->buildAttributes($attributes).'></div>';
return $html;
......
......@@ -52,7 +52,7 @@ class NoCaptchaServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind('captcha', function ($app) {
$this->app->singleton('captcha', function ($app) {
return new NoCaptcha(
$app['config']['captcha.secret'],
$app['config']['captcha.sitekey']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment