Move config::set calls into single helper function
This commit is contained in:
parent
ca6a4327e9
commit
23e6e0510b
2 changed files with 31 additions and 59 deletions
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue