mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:04:03 +00:00
Add CreateTenant command, fix TenantList output
This commit is contained in:
parent
40f8fa346e
commit
8c18836cca
2 changed files with 48 additions and 1 deletions
47
src/Commands/CreateTenant.php
Normal file
47
src/Commands/CreateTenant.php
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
|
class CreateTenant extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'tenants:create
|
||||||
|
{--d|domain=* : The tenant\'s domains.}
|
||||||
|
{data?* : The tenant\'s data. Separate keys and values by `=`, e.g. `plan=free`.}';
|
||||||
|
|
||||||
|
protected $description = 'Create a tenant.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$tenant = Tenant::new()
|
||||||
|
->withDomains($this->getDomains())
|
||||||
|
->withData($this->getData())
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$this->info($tenant->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDomains(): array
|
||||||
|
{
|
||||||
|
return $this->option('domain');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData(): array
|
||||||
|
{
|
||||||
|
return array_reduce($this->argument('data'), function ($data, $pair) {
|
||||||
|
[$key, $value] = explode('=', $pair, 2);
|
||||||
|
$data[$key] = $value;
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ class TenantList extends Command
|
||||||
{
|
{
|
||||||
$this->info('Listing all tenants.');
|
$this->info('Listing all tenants.');
|
||||||
tenancy()->all()->each(function ($tenant) {
|
tenancy()->all()->each(function ($tenant) {
|
||||||
$this->line("[Tenant] id: {$tenant['id']} @ ", implode('; ', $tenant->domains));
|
$this->line("[Tenant] id: {$tenant['id']} @ " . implode('; ', $tenant->domains));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue