I am trying to set up multiple environments on a Laravel 4 app, and naturally different Databases depending on which environment we are on.
For my local machine, I set up a virtual host for "local.elders.dev"
Unfortunately, for some reason the following code is not working.
$env = $app->detectEnvironment(array(
'local' => array('http://local.elders.dev'),
));
Maybe I need to run an artisan command or something else. I feel I am close, but not quite there yet !
Thanks to all !
Another method is to use the name of the folder the project is in. This works in console and web. I found this to be the only reliable way if different environments are hosted on the same server.
$env = $app->detectEnvironment(array(
'staging' => strpos(getcwd(), '/staging')>-1,
'acceptance' => strpos(getcwd(), '/acceptance')>-1,
'production' => strpos(getcwd(), '/production')>-1,
));
A big advantage is that you can move staging to production by simply renaming or copying the project folder without changing files, db records or environment variables.
I know this is answered but for others looking for a solution...
My environment detection setting looks like this:
$env = $app->detectEnvironment(array(
// Development
// any machine name with the term "local" will use the local environment
'local' => array('*local*'),
// Stage
// any machine name with the term "stage" will use the stage environment
'stage' => array('*stage*')
// Production
// production is default, so we don't need to specify any detection
));
This is handy because it will work on any project as long as I use "local" for development (like "localhost", "localhost:8000", "my.app.local", etc.). Same goes for "stage". And production is default so anything without "local" or "stage" works for production.
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