Becouse I developing on my notebook and on my destkop, too I want to use an sql server what I can connect anytime.
I want to connect to this when I'm on the development enviroment and use an other when I'm on production. How can I achieve this?
I tried this in the config/database
:
if('env' == 'development'){
$host = 'mysqlserver.alias.com';
$database = 'mydb';
$username = 'myuname';
$password = 'mypwd';
} else {
$host = whatsintheenv;
$database = whatsintheenv;
$username = whatsintheenv;
$password = whatsintheenv;
}
In Laravel you can check environment by:
Laravel makes use of the PHP dotenv library - https://github.com/vlucas/phpdotenv.
This means you'll want to create a
.env
file on each of your machines with the connection that you want to use. Then in your code, you can load these values usingApp:environment('ENV_VALUE')
.This should be handled by your environment configuration via the
.env
file.If you don't have a
.env
file yet, make a copy of.env.example
. In there, you'll find these settings:Simply modify these values to connect to the correct database server.
The
.env
file is excluded from source control, so your notebook and your desktop can have different contents in this file.