3 months ago

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

Posted 3 months ago by Brainmaniac

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

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?

Please sign in or create an account to participate in this conversation.