Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Must supply cloudName when laravel config is cached #104

Open
meyer59 opened this issue Oct 23, 2023 · 2 comments
Open

Error Must supply cloudName when laravel config is cached #104

meyer59 opened this issue Oct 23, 2023 · 2 comments

Comments

@meyer59
Copy link

meyer59 commented Oct 23, 2023

Hi
We are using the UploadApi class to upload files to Cloudinary and we run into an Exception Must supply cloudName when we cache the laravel config (php artisan config:cache).
When the config is cached in laravel the env should no be used but the config file directly, i can see in the code (cloudinary/cloudinary_php/src/Configuration/Configuration.php:164) that you guys use getenv

@unicodeveloper
Copy link
Collaborator

Please can you shed more light on this? The part of the code you are referencing is in the PHP library. Do you want to raise an issue there? https://github.com/cloudinary/cloudinary_php

@meyer59
Copy link
Author

meyer59 commented Oct 31, 2023

I think the main issue is that the main package use getenv() putenv() to setup the env variables. When you cache the Laravel config, the env file doesn't exist anymore so calling getenv() won't work.
That's the reason why in you code you never use env() directly but always value from config files
From the doc

Once the configuration has been cached, your application's .env file will not be loaded by the framework during requests or Artisan commands; therefore, the env function will only return external, system level environment variables.

For this reason, you should ensure you are only calling the env function from within your application's configuration (config) files. You can see many examples of this by examining Laravel's default configuration files. Configuration values may be accessed from anywhere in your application using the config function described above.

We solved this issue by re-injecting the config on the fly,
app(UploadApi::class, ['configuration' => config('cloudinary.cloud_url')])->upload(...)

Maybe this package can register those instance in the Container and injecting the config properly so we don't have to do it manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants