I want something like this:
JavaScript
x
env('APP_ENV');
setenv('APP_ENV', 'testing');
env('APP_ENV');
Output :
JavaScript
staging
testing
I find one answer How to change variables in the .env file dynamically in Laravel? but here .env is saved permanently, I don’t want to save permanently. How phpunit is doing this ? Because I can put in phpunit.xml this :
JavaScript
<php>
<env name="APP_ENV" value="testing"/>
</php>
.
And env(‘APP_ENV’) gives me ‘testing’…
Advertisement
Answer
putenv() work like a charm :
JavaScript
echo env('APP_ENV');
putenv('APP_ENV=testing');
echo env('APP_ENV');
Output:
JavaScript
staging
testing
.env file is unattached …