Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default environment in Laravel 4

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?

like image 369
Collin James Avatar asked Dec 18 '13 22:12

Collin James


People also ask

How do I change environment variables in Laravel dynamically?

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 .

What is environment configuration in Laravel?

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.

Where is .ENV file in Laravel?

In a fresh Laravel installation, the root directory of your application will contain a . env. example file that defines many common environment variables.


1 Answers

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),

));
like image 191
rabin Avatar answered Sep 29 '22 13:09

rabin