In Laravel 4 the default configuration environment is 'production'. This means that if you run an artisan command without the --env
option, it assumes the production configuration. This can be seen in \Illuminate\Foundation\Application::detectWebEnvironment()
which is called by detectConsoleEnvironment()
when no --env
option is set.
This behavior has become a risk with my development environment. It's really easy to forget the --env option and, say, unintentionally run a migration on your production database. (Yes, that happened but thankfully it was a minor change.) I'm close to just renaming my production environment config to 'real-production' but it seems like there should be a more elegant solution.
TL;DR
How can I change the default environment in Laravel 4 such that artisan commands do not run on production by default?
A simple way to update the . env key value in laravel is to add the below code in the controller function where you want to change . env values. $key = 'VARIABLE_NAME'; $value = 'NEW VALUE'; file_put_contents(app()->environmentFilePath(), str_replace($key .
Laravel configuration allows you to define per-environment configuration with the excellent vlucas/phpdotenv package. If you are new to Laravel, you might not yet know how you can create your configuration files in your projects and a few other helpful things that will help you master configuration.
In a fresh Laravel installation, the root directory of your application will contain a . env. example file that defines many common environment variables.
You can try modifying app/start.php file to add second parameter on desired environment as TRUE i.e. to enable local environment it looks like
$env = $app->detectEnvironment(array(
'local' => array('homestead',true),
));
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