-
-
Save reinink/6229c9fca8476e720951 to your computer and use it in GitHub Desktop.
Add environment var config to Laravel 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_ENV=local | |
APP_DEBUG=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"vlucas/phpdotenv": "~1.1" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/config/database.php | |
return array( | |
'connections' => array( | |
'mysql' => array( | |
'driver' => 'mysql', | |
'host' => getenv('DB_HOST'), | |
'database' => getenv('DB_DATABASE'), | |
'username' => getenv('DB_USERNAME'), | |
'password' => getenv('DB_PASSWORD'), | |
'charset' => 'utf8', | |
'collation' => 'utf8_unicode_ci', | |
'prefix' => '', | |
), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// bootstrap/start.php | |
$env = $app->detectEnvironment(function () { | |
try { | |
Dotenv::load(__DIR__.'/../'); | |
} catch (Exception $e) { | |
// No .env file found | |
} | |
return getenv('APP_ENV') ? getenv('APP_ENV') : 'production'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And a nice helper.