How to Use Local Environment as Default in Laravel Artisan CLI
I have to say, I absolutely LOVE Laravel – everything about it.
One of my favorite features is the ability to separate your app into local/production versions.
I use a lot of packages for development, that I just don’t need on my production version of the app. How do I resolve this? By using two different environments w/ different App.php configs. Read my tutorial on this here.
You might find that this only works for your app when running it in the browser. Here’s how to make sure that the local environment is ALSO set for command-line e.g. Artisan and Tinker.
One option of course is to do:
C:\ampps\www\myapp php artisan .... --env=local
But who wants to write –env=local after EVERY artisan command? I am a pragmatist and believe in using technology to my advantage. This is great when needing to switch back and forth for a minute, but when doing it all the time you need an alternative.
C:\ampps\www\myapp $ php artisan tinker > var_dump(gethostname()); string(9) "PatrickPC" >exit();
next add “PatrickPC” to bootstrap/start.php
$env = $app->detectEnvironment( array( 'local' => array('localhost', '*.dev', 'PatricksPC'), 'production' => array('mydomain.com') ));
Now artisan should run w/ local environment as default when on this machine, let’s test it:
C:\ampps\www\myapp $ php artisan env Current application environment: local C:\ampps\www\myapp
Got questions? Leave a comment!