Created
October 28, 2017 19:57
-
-
Save deleugpn/3ad8e61e5a1a865199a4f2a5b34a7190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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