1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-14 17:04:03 +00:00

DatabasePreparationTest

This commit is contained in:
Samuel Štancl 2020-05-12 03:14:08 +02:00
parent 86a98b2bc8
commit 3c4d2189dc
4 changed files with 148 additions and 25 deletions

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Console\Seeds\SeedCommand;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseSeeded;
use Stancl\Tenancy\Traits\HasATenantsOption;
@ -54,7 +55,12 @@ class Seed extends SeedCommand
return;
}
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
tenancy()
->query()
->when($this->option('tenants'), function ($query) {
$query->whereIn(tenancy()->model()->getTenantKeyName(), $this->option('tenants'));
})
->each(function (TenantWithDatabase $tenant) {
$this->line("Tenant: {$tenant['id']}");
$tenant->run(function () {