framework: config('value') is not working on cron
- Laravel Version: 5.3.22
- PHP Version: 7.0.11
- OS: ubuntu 14.04.4
Description:
I was trying to send an email from a job. It was actually calls an external API and I store the URL in config/services.php
file like this-
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'sparkpost' => [
'secret' => env('SPARKPOST_SECRET'),
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
'sm_api' => env('SM_API', 'api-url'),
];
I also use this sm_api value from frontend like this config('services.sm_api')
. There it works like a charm. but when I try to use the same value from a laravel job class, which actually dispatched from Redis queue server, the same function call returns null. I tried to log the whole config()->all()
and it returns the predefined values, except sm_api
.
array (
'mailgun' => array (
'domain' => NULL,
'secret' => NULL,
),
'ses' => array (
'key' => NULL,
'secret' => NULL,
'region' => 'us-east-1',
),
'sparkpost' => array (
'secret' => NULL,
),
'stripe' => array (
'model' => 'App\\User',
'key' => NULL,
'secret' => NULL,
),
)
It also shows mailgun’s domain and secret value to null though I set it in the .env
file. I also log the env('SM_API')
value, and it works from the same job. So, the problem is I can bear with env('SM_API')
from the job, but I can use mail, as the mailgun driver and key is null. But all this works fine from the frontend. I also tried it in php artisan tinker
, and it works perfectly.
I searched on google for this and found this. This issue suggest to use php artisan config:cache
to resolve this. I tried this as well. But nothing happens.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (8 by maintainers)
In my case
php artisan config:clear
works.You can remove it with
php artisan config:clear
or manually delete the filebootstrap/cache/config.php
just stop supervisorctl and start it again.
It’s happen due to cache of supervisorctl
For me,
php artisan config:cache
worked. (config:clear
didn’t). We get a lot of config related issues for some reason. Something is fishy with caching.@sisve, I removed it. then create it again with
php artisan config:cache
. But no luck.