mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 19:54:04 +00:00
Add and use getWithPendingOption method
This commit is contained in:
parent
09bb5326c7
commit
040c42d325
1 changed files with 22 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Concerns;
|
|||
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Stancl\Tenancy\Database\Concerns\PendingScope;
|
||||
|
||||
/**
|
||||
* Adds 'tenants' and 'with-pending' options.
|
||||
|
|
@ -16,10 +17,29 @@ trait HasTenantOptions
|
|||
{
|
||||
return array_merge([
|
||||
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null],
|
||||
['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', config('tenancy.pending.include_in_queries')],
|
||||
['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', false],
|
||||
], parent::getOptions());
|
||||
}
|
||||
|
||||
protected function getWithPendingOption(): bool
|
||||
{
|
||||
$optionPassedWithoutArgument = is_null($this->option('with-pending'));
|
||||
$optionPassedWithArgument = is_string($this->option('with-pending'));
|
||||
|
||||
// E.g. tenants:run --with-pending
|
||||
if ($optionPassedWithoutArgument) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// E.g. tenants:run --with-pending=false
|
||||
if ($optionPassedWithArgument) {
|
||||
return filter_var($this->option('with-pending'), FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
// Option not passed, e.g. tenants:run
|
||||
return config('tenancy.pending.include_in_queries');
|
||||
}
|
||||
|
||||
protected function getTenants(): LazyCollection
|
||||
{
|
||||
return tenancy()
|
||||
|
|
@ -28,7 +48,7 @@ trait HasTenantOptions
|
|||
$query->whereIn(tenancy()->model()->getTenantKeyName(), $this->option('tenants'));
|
||||
})
|
||||
->when(tenancy()->model()::hasGlobalScope(PendingScope::class), function ($query) {
|
||||
$query->withPending($this->option('with-pending'));
|
||||
$query->withPending($this->getWithPendingOption());
|
||||
})
|
||||
->cursor();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue