mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 01:44:04 +00:00
pending tenants: minor cleanup
This commit is contained in:
parent
0dc187510b
commit
d274d8c902
4 changed files with 13 additions and 33 deletions
|
|
@ -18,7 +18,7 @@ trait HasTenantOptions
|
|||
{
|
||||
return array_merge([
|
||||
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, 'The tenants to run this command for. Leave empty for all tenants', null],
|
||||
['with-pending', null, InputOption::VALUE_NONE, 'Include pending tenants in query'],
|
||||
['with-pending', null, InputOption::VALUE_NONE, 'Include pending tenants in query'], // todo@pending should we also offer without-pending? if we add this, mention in docs
|
||||
], parent::getOptions());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,6 @@ use Illuminate\Database\Eloquent\Scope;
|
|||
|
||||
class PendingScope implements Scope
|
||||
{
|
||||
/**
|
||||
* All of the extensions to be added to the builder.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $extensions = ['WithPending', 'WithoutPending', 'OnlyPending'];
|
||||
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
|
|
@ -32,26 +25,21 @@ class PendingScope implements Scope
|
|||
}
|
||||
|
||||
/**
|
||||
* Extend the query builder with the needed functions.
|
||||
* Add methods to the query builder.
|
||||
*
|
||||
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function extend(Builder $builder)
|
||||
public function extend(Builder $builder): void
|
||||
{
|
||||
foreach ($this->extensions as $extension) {
|
||||
$this->{"add{$extension}"}($builder);
|
||||
}
|
||||
$this->addWithPending($builder);
|
||||
$this->addWithoutPending($builder);
|
||||
$this->addOnlyPending($builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the with-pending extension to the builder.
|
||||
*
|
||||
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addWithPending(Builder $builder)
|
||||
protected function addWithPending(Builder $builder): void
|
||||
{
|
||||
$builder->macro('withPending', function (Builder $builder, $withPending = true) {
|
||||
if (! $withPending) {
|
||||
|
|
@ -63,13 +51,9 @@ class PendingScope implements Scope
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the without-pending extension to the builder.
|
||||
*
|
||||
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addWithoutPending(Builder $builder)
|
||||
protected function addWithoutPending(Builder $builder): void
|
||||
{
|
||||
$builder->macro('withoutPending', function (Builder $builder) {
|
||||
$builder->withoutGlobalScope(static::class)
|
||||
|
|
@ -81,13 +65,9 @@ class PendingScope implements Scope
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the only-pending extension to the builder.
|
||||
*
|
||||
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addOnlyPending(Builder $builder)
|
||||
protected function addOnlyPending(Builder $builder): void
|
||||
{
|
||||
$builder->macro('onlyPending', function (Builder $builder) {
|
||||
$builder->withoutGlobalScope(static::class)->whereNotNull($builder->getModel()->getColumnForQuery('pending_since'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue