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

JeremyHargis's avatar

Setting Configuration Options for PHP Library (the right way)

Hello.

I would like to include Cloudinary's PHP library (http://cloudinary.com/documentation/php_integration#getting_started_guide) in my Laravel 5.1 project. I am new to PHP and Laravel and am still trying to figure everything out. I see that I can set the various configuration options on the fly every time I call a function from the library, but I'd like to know the "correct" way to configure this library with Laravel. It seems like I should be able to set some of these configuration options somewhere else in my Laravel project so that when I call the method, all the options are already set (similar to the way configuration options for other aspects of Laravel are set in the files in the config directory).

Can anyone offer any pointers on this? Thanks.

0 likes
3 replies
accent-interactive's avatar

You can set the more static configuration options in a config file. Create config/cloudinary.php and have it terun the options you need.

return [
    'cloud_name' => 'yourcloud_name',
    'api_key' => 'yourapikey',
    'api_secret' => 'yourapisecret',
    // Etc.
];

Then, from where you use Cloudinary, just cal them like this:

Cloudinary::config(array(
    'cloud_name' => config('cloudinary.cloud_name'),
    'api_key' => config('cloudinary.cloud_name'),
    'api_secret' => config('cloudinary.cloud_name')
));
JeremyHargis's avatar

joostvanveen,

Thanks for your help. That makes sense. It's too bad that won't really save my application any complexity as I'm still setting those options each time I have to use Cloudinary. I was really wondering if there was a way within Laravel that I could set these options and just have that configuration be set automatically should I call any Cloudinary functions (it seems like such a path would be consistent with the overall structure of Laravel). It is possible there isn't really a way to do what I'm thinking.

Thanks again.

Please or to participate in this conversation.