mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 22:14:03 +00:00
* install PHP CS Fixer * Fix styling * remove StyleCI config * use config from archtechx/template * Fix styling * added `php-cs-fixer` * Update .php-cs-fixer.php * added GitHub token * Update ci.yml * Update ci.yml * Update ci.yml * php-cs-fixer workflow same as template Co-authored-by: Erik Gaal <me@erikgaal.nl> Co-authored-by: erikgaal <erikgaal@users.noreply.github.com>
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Database\ConnectionResolverInterface;
|
|
use Illuminate\Database\Console\Seeds\SeedCommand;
|
|
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
|
use Stancl\Tenancy\Events\DatabaseSeeded;
|
|
use Stancl\Tenancy\Events\SeedingDatabase;
|
|
|
|
class Seed extends SeedCommand
|
|
{
|
|
use HasATenantsOption;
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Seed tenant database(s).';
|
|
|
|
protected $name = 'tenants:seed';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(ConnectionResolverInterface $resolver)
|
|
{
|
|
parent::__construct($resolver);
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
foreach (config('tenancy.seeder_parameters') as $parameter => $value) {
|
|
if (! $this->input->hasParameterOption($parameter)) {
|
|
$this->input->setOption(ltrim($parameter, '-'), $value);
|
|
}
|
|
}
|
|
|
|
if (! $this->confirmToProceed()) {
|
|
return;
|
|
}
|
|
|
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
|
$this->line("Tenant: {$tenant->getTenantKey()}");
|
|
|
|
event(new SeedingDatabase($tenant));
|
|
|
|
// Seed
|
|
parent::handle();
|
|
|
|
event(new DatabaseSeeded($tenant));
|
|
});
|
|
}
|
|
}
|