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

BikashKatwal's avatar

access config/stripe.php value in controller

I have created stripe.php in app/config/stripe.php.

<?php
return array(
    // Stripe keys
    'stripe' => array(
        'secret' => 'sk_test_TWxxxxxxxx',
        'public' => 'pk_test_bxxxxxxxxxxxxx'
    ),

);

I want to render stripe.secret in Controller. How can I render the key in Home Controller.

In HomeController,

\Stripe\Stripe::setApiKey('I need stripe.secret key here');
0 likes
8 replies
BikashKatwal's avatar

@ksparkar I tried \Stripe\Stripe::setApiKey(config('stripe.stripe.secret')); but not getting the value. How the config/stripe.php file is linked to controller.

Snapey's avatar

I think you have an extra level of nesting

As you have it now, it would be config('stripe.stripe.secret')

Test it in tinker.

>>> config('stripe')
ksparkar's avatar

config() is a global helper so you don't need to worry about linking it. I think you have some other issue, maybe try to output some other config value as a test ex. config('app.name')

BikashKatwal's avatar

@snapey $value = config('stripe.stripe.secret'); is not working. I was thinking we need to "use \App\config", something like this to get the value , but I am not sure how to connect controller and config.

BikashKatwal's avatar

@ksparkar and @snapey I am using laravel 4.2. Is it because of version it is not rendering any value with the above mentioned code. How we can do in 4.2 and even $value =config('app.name'); is not working.

Snapey's avatar

4.2? Would have been useful to know this from the start

I don't think I would be building something using stripe with such an old and unsupported version.

Please or to participate in this conversation.