anam-hossain / captcha

reCAPTCHA V2 and invisible reCAPTCHA for Laravel.
MIT License
28 stars 6 forks source link

env function in code #2

Closed speedykhr closed 5 years ago

speedykhr commented 6 years ago

Hi and thanks for the nice wrapper,

I had a problem with the keys, that were stored in the .env file. The keys were retrieved in your Captcha Code on two positions (e.g. anam/captcha/src/Captcha.php) by means of the env() function. Everything worked as described until I fired up php artisan config:cache.

From then on, the app told me that the site_key or secret key was missing. This could be fixed by using php artisan config:clear.

However, according to the laravel documentation (https://laravel.com/docs/5.5/helpers#method-env) there is a problem when using the env() function in other files than the config file in combination with the config caching feature. In that case the function will return null.

Hence I would suggest to write a short config file load the keys from .env using the env() function and use the config() helper within your classes to get the keys from there.

That worked for me. So I can use the cached and non-cached config.

Best regards

speedy

Config example, with google test keys: captcha.php.zip

anam-hossain commented 6 years ago

@speedykhr Can you create a pull request?