Edujugon / laravel-google-ads

Google Adwords API for Laravel
MIT License
68 stars 23 forks source link

php artisan config:cache #47

Open martijnimhoff opened 4 years ago

martijnimhoff commented 4 years ago

I've setup my google-ads.php config file with env() helpers, because I want to follow the good practice of not putting credentials in my repo history.

However when I run php artisan config:cache, the google ads package isn't working anymore. I guess that the package is still looking in the google-ads.php file, which now returns null on each value, because when you run php artisan config:cache. The env() will always return null.

Techworker commented 4 years ago

Yes, it seems to work with an include on the config file instead of the laravel config() function. See here:

https://github.com/Edujugon/laravel-google-ads/blob/master/src/Support/helpers.php#L52-L67

There is a workaround, you might give this a try in your google-ads.php config file:


return [
    'env' => 'test',
    'test' => [
        'developerToken' => env('GOOGLE_ADS_DEVELOPER_TOKEN', config('google-ads.test.developerToken')),
        'clientCustomerId' => env('GOOGLE_ADS_CUSTOMER_ID', config('google-ads.test.clientCustomerId')),
    // ...
    ],
];
martijnimhoff commented 4 years ago

Looks nasty, but it might work.

I've tried to recreate the error of this issue, but it seems to be working fine atm. Even without the workaround, it's still able to get the filled contents of google-ads.php.

It seems the behavior of env() has changed. Still it would be better to use config() because of the performance boost from php artisan config:cache.

mwargan commented 3 years ago

Yes, it seems to work with an include on the config file instead of the laravel config() function. See here:

https://github.com/Edujugon/laravel-google-ads/blob/master/src/Support/helpers.php#L52-L67

There is a workaround, you might give this a try in your google-ads.php config file:

return [
    'env' => 'test',
    'test' => [
        'developerToken' => env('GOOGLE_ADS_DEVELOPER_TOKEN', config('google-ads.test.developerToken')),
        'clientCustomerId' => env('GOOGLE_ADS_CUSTOMER_ID', config('google-ads.test.clientCustomerId')),
    // ...
    ],
];

This didn't work for me since the test variables are also in the .env file, and thus using env(). I can +1 that the issue only occurs when the config is cached.