Move config::set calls into single helper function

This commit is contained in:
Dane Everitt 2017-04-13 23:19:01 -04:00
parent ca6a4327e9
commit 23e6e0510b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 31 additions and 59 deletions

View file

@ -24,6 +24,8 @@
namespace Pterodactyl\Models;
use Crypt;
use Config;
use Illuminate\Database\Eloquent\Model;
class DatabaseHost extends Model
@ -62,6 +64,26 @@ class DatabaseHost extends Model
'node_id' => 'integer',
];
/**
* Sets the database connection name with the details of the host.
*
* @param string $connection
* @return void
*/
public function setDynamicConnection($connection = 'dynamic')
{
Config::set('database.connections.' . $connection, [
'driver' => 'mysql',
'host' => $this->host,
'port' => $this->port,
'database' => 'mysql',
'username' => $this->username,
'password' => Crypt::decrypt($this->password),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]);
}
/**
* Gets the node associated with a database host.
*