Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Brainmaniac's avatar

Reasons for erratic behaviour loading constants from env->config->blade?

I am running Laravel Framework 5.8.37 (Haven't had time to upgrade yet...)

I have Sstripe as a payment solution in my laravel app. After some refactoring I am about to re-implement my payment stuff from Stripe.

I keep all my keys and stuff in the .env. like:

STRIPE_PUB_KEY= pk_test_MyKeYs
STRIPE_SECRET_KEY= sk_test_MyKeYs
STRIPE_END_POINT_SECRET = whsec_MyKeYs

In the app.config I define them:

'stripe_pub_key' => env('STRIPE_PUB_KEY'),
'stripe_secret_key' => env('STRIPE_SECRET_KEY'),
'stripe_end_point_secret' => env('STRIPE_END_POINT_SECRET')	

Then from my code I call:

var stripe = Stripe("{{ config('app.stripe_pub_key') }}");

Everything SHOLD work. But what happens? I get the error:

Uncaught IntegrationError: Please call Stripe() with your publishable key. You used an empty string.

The call to the config returns empty string! Strange, well it will get worse. To be able to test better I've just added this to my blade:

<h1>My response:{{ config('app.stripe_pub_key') }}</h1>

It does indeed return empty string. Now to the real strangeness. If I change to:

<h1>My response:{{ config('app.stripe_secret_key') }}</h1>

... just to test. It returns the secret key!!! 😤 - It also works with the end point secret. It seems to just be the pub_key that does not work... Also if I make a random new one it does not seem to work...

What can this be?

0 likes
2 replies
Tippin's avatar
Tippin
Best Answer
Level 13

@brainmaniac Try caching the config files first to update your cached configs, assuming you already ran that command in the past. If on local, you can also clear your config cache and have it read directly from your .env

php artisan config:clear
php artisan config:cache
Brainmaniac's avatar

🎉🤩 Thank you!! Assumed there was something with some cache but did not know this! Thank you!

Please or to participate in this conversation.