-
-
Save dariodiaz/8791159 to your computer and use it in GitHub Desktop.
laravel: environment configuration
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
Create a .environment file in the root of your application and define your environment and gitignore it: | |
``` | |
return array( | |
'LARAVEL_ENV' => 'development', | |
'POSTGRESQL.HOST' => 'localhost', | |
'POSTGRESQL.DATABASE_NAME' => 'laraveldatabase', | |
'POSTGRESQL.DATABASE_USER' => 'laraveluser', | |
'POSTGRESQL.DATABASE_PASSWORD' => '!Bassw0rT', | |
); | |
``` | |
Load it in Laravel right before `$app->detectEnvironment()`: | |
``` | |
foreach(require __DIR__.'/../.environment' as $key => $value) | |
{ | |
putenv(sprintf('%s=%s', $key, $value)); | |
} | |
``` | |
Then just use it everywhere: | |
``` | |
<?php | |
return array( | |
'connections' => array( | |
'postgresql' => array( | |
'driver' => 'pgsql', | |
'host' => getenv('POSTGRESQL.HOST'), | |
'database' => getenv('POSTGRESQL.DATABASE_NAME'), | |
'username' => getenv('POSTGRESQL.DATABASE_USER'), | |
'password' => getenv('POSTGRESQL.DATABASE_PASSWORD'), | |
'charset' => 'utf8', | |
'prefix' => '', | |
'schema' => 'public', | |
), | |
), | |
); | |
``` | |
Better than use it all in the .htaccess file, IMO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment