stratagy for app config setting
Many, if not all, applications require specific setting, and these are usually different depending on the environment or client where you might deploy. I had always used the “.env” file and resorted to using env('value',default) where ever I needed it. After some feedback, now I think this might not be the complete and/or best solution and is not guaranteed to work! for example if you run php artisan config:cache, env() returns null, so be careful ! I’m know using the following> Apart from having setting in the .env file, also adding corresponding entries into the config/app.php or a file of your preference. By using this approach, upon passing to production you should run
php artisan config:cache
this will merge all files in the config folder and produce a corresponding config.php file under bootstrap folder. Now Insted of using env('setting1') just use config('app.setting1') which is much faster. Some added bonuses are now you can also specify array and cast variables in the app.php file. If a setting is permanent or you just want to add it so it’s not HARD coded you can just omit the setting in .env and just add it into app.php.
.env
setting1 = "some setting"
setting2 = false
setting3 = 200
config/app.php
'setting1' => env('setting1','some default value'),
setting2 => env('setting2',false),
setting3 => env('setting3',null),
Let me know what you think, or if there is room for improvement.
Please or to participate in this conversation.