Last active
June 13, 2018 02:13
-
-
Save jobcerto/bc89ffc7015b4fc2d7a27ca22cd9472e to your computer and use it in GitHub Desktop.
This file contains 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 | |
use Hyn\Tenancy\Contracts\Repositories\CustomerRepository; | |
use Hyn\Tenancy\Contracts\Repositories\HostnameRepository; | |
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository; | |
use Hyn\Tenancy\Models\Customer; | |
use Hyn\Tenancy\Models\Hostname; | |
use Hyn\Tenancy\Models\Website; | |
use Illuminate\Database\Seeder; | |
class BuildDatabasesForTenants extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
$customers = [ | |
['database' => 'customer_foo_tenancy', 'domain' => 'foo.multi-tenancy.job', 'name' => 'Foo Customer', 'email' => 'customer@foo.com'], | |
['database' => 'customer_bar_tenancy', 'domain' => 'bar.multi-tenancy.job', 'name' => 'Bar Customer', 'email' => 'customer@bar.com'], | |
['database' => 'customer_baz_tenancy', 'domain' => 'baz.multi-tenancy.job', 'name' => 'Baz Customer', 'email' => 'customer@baz.com'], | |
]; | |
foreach ($customers as $customer) { | |
/* | |
|-------------------------------------------------------------------------- | |
| CREATE THE WEBSITE | |
|-------------------------------------------------------------------------- | |
*/ | |
$website = new Website(['uuid' => $customer['database']]); | |
app(WebsiteRepository::class)->create($website); | |
/* | |
|-------------------------------------------------------------------------- | |
| CREATE THE HOSTNAME | |
|-------------------------------------------------------------------------- | |
*/ | |
$hostname = new Hostname(['fqdn' => $customer['domain']]); | |
app(HostnameRepository::class)->attach($hostname, $website); | |
/* | |
|-------------------------------------------------------------------------- | |
| CREATE THE CUSTOMER | |
|-------------------------------------------------------------------------- | |
*/ | |
$customer = new Customer(['name' => $customer['name'], 'email' => $customer['email']]); | |
app(CustomerRepository::class)->create($customer); | |
/* | |
|-------------------------------------------------------------------------- | |
| SAVE THE CUSTOMER WITH HIS HOSTNAME AND WEBSITE | |
|-------------------------------------------------------------------------- | |
*/ | |
$hostname->customer()->associate($customer)->save(); | |
$website->customer()->associate($customer)->save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment