Skip to content

Commit

Permalink
Update for multiple app('captcha')->display() on the same page (#57)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
seltix5 authored and anhskohbo committed Jan 1, 2017
1 parent 4fb2be4 commit f5befe2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/NoCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class NoCaptcha
*/
protected $http;

/**
* API requested control
*/
protected $api_requested = false;

/**
* NoCaptcha.
*
Expand All @@ -53,7 +58,11 @@ public function display($attributes = [], $lang = null)
{
$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;
Expand Down
2 changes: 1 addition & 1 deletion src/NoCaptchaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function bootConfig()
*/
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']
Expand Down

0 comments on commit f5befe2

Please sign in to comment.