In Laravel there is the file .env
.
In it I define my database connections, email, among other things.
Let's suppose I have 3 connections:
- Localhost
- Homologation
- Production
When I want to work on localhost I change the APP_ENV
variable. I leave the value of this as local
.
When I want to upload the files in the homologation repository I leave the value of this variable as homo
, and I make git push origin master
.
When I want to go up in production I change the value to production
and I make push
again.
All this for connection to file database.php
. It was the best solution I found.
'mysql' => [
'driver' => 'mysql',
'host' => (env('APP_ENV') == 'local') ? env('DB_HOST_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_HOST_HOMO') : env('DB_HOST')),
'database' => (env('APP_ENV') == 'local') ? env('DB_DATABASE_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_DATABASE_HOMO') : env('DB_DATABASE')),
'username' => (env('APP_ENV') == 'local') ? env('DB_USERNAME_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_USERNAME_HOMO') : env('DB_USERNAME')),
'password' => (env('APP_ENV') == 'local') ? env('DB_PASSWORD_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_PASSWORD_HOMO') : env('DB_PASSWORD')),
],
Can you automate this via git
or otherwise?
NOTE: I created 2 repositories in GitHub, one of Homologation and one of Production to upload the project.