1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:14:03 +00:00
tenancy/src/Concerns/HasTenantOptions.php
lukinovec 7d3298c6bb
Improve code of pending tenants (#1025)
* Remove `--all` option from ClearPendingTenants

* Improve query formatting

* Remove redundant test

* Convert time constrait options to int

* Improve CreatePendingTenants success message
2022-11-29 09:31:07 +01:00

42 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Concerns;
use Illuminate\Support\LazyCollection;
use Stancl\Tenancy\Database\Concerns\PendingScope;
use Symfony\Component\Console\Input\InputOption;
/**
* Adds 'tenants' and 'with-pending' options.
*/
trait HasTenantOptions
{
protected function getOptions()
{
return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null],
['with-pending', null, InputOption::VALUE_NONE, 'include pending tenants in query'],
], parent::getOptions());
}
protected function getTenants(): LazyCollection
{
return tenancy()->query()
->when($this->option('tenants'), function ($query) {
$query->whereIn(tenancy()->model()->getTenantKeyName(), $this->option('tenants'));
})
->when(tenancy()->model()::hasGlobalScope(PendingScope::class), function ($query) {
$query->withPending(config('tenancy.pending.include_in_queries') ?: $this->option('with-pending'));
})
->cursor();
}
public function __construct()
{
parent::__construct();
$this->specifyParameters();
}
}