I'm wondering if there's a way in Laravel to specify a set of env files to load. My exact problem is I want to add something like a suffix to all my .js
and .css
resources. Ideally I'd have a suffix like the release date because it would be ok for these files to be cached within the same release but I would like the caches to be invalidated on the next release. However I want to avoid reading, modifying and saving the .env
file if possible and would instead prefer to create a new file e.g. .env.rdate
which would be generated via a script, e.g.
echo APP_RELEASE_DATE=`date +%s` > env.rdate
or something like this. Is this at all possible or do I have to read/update/write the .env file instead?
One solution is to have multiple . env files which each represent different environments. In practice this means you create a file for each of your environments: .
Using environment variables is a somewhat common practice during Development but it is actually not a healthy practice to use with Production. While there are several reasons for this, one of the main reasons is that using environment variables can cause unexpected persistence of variable values.
You can create an. env file in the application's root directory that contains key/value pairs defining the project's required environment variables.
Create your .env.rdate file next to .env file.
Put this to your AppServiceProvider boot method:
$dotenv = new \Dotenv\Dotenv(base_path(),'.env.rdate');
$dotenv->overload();
After you can use in your project:
ENV('APP_RELEASE_DATE')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With