Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Created October 28, 2017 19:57
Show Gist options
  • Save deleugpn/3ad8e61e5a1a865199a4f2a5b34a7190 to your computer and use it in GitHub Desktop.
Save deleugpn/3ad8e61e5a1a865199a4f2a5b34a7190 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models\Main;
use App\Models\MainModel;
use Illuminate\Support\Facades\Config;
class Company extends MainModel
{
/**
* Establish a connection with the tenant's database.
*/
public function connect()
{
if (! $this->connected()) {
tenant_connect(
$this->hostname,
$this->username,
$this->password,
$this->database
);
}
}
/**
* Check if the current tenant connection settings matches the company's database settings.
*
* @return bool
*/
private function connected()
{
$connection = Config::get('database.connections.tenant');
return $connection['username'] == $this->username &&
$connection['password'] == $this->password &&
$connection['database'] == $this->database;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment