The easiest solution is to configure the database at run time. Laravel can expect these settings to be loaded from a file config/database.php, but that does not mean that you cannot install or change them later.
The configuration loaded from config/database.phpis saved as databasein the Laravel configuration. This means that the array connectionsinside config/database.phpis stored in a file database.connections.
Thus, you can easily override / modify these connections as follows:
Config::set("database.connections.mysql", [
"host" => "...",
"database" => "...",
"username" => "...",
"password" => "..."
]);
From now on, all Eloquent models using this connection mysqlwill use this new database connection configuration.
I would recommend doing this at a service provider, if possible.
source
share