1
0
Fork 0
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:
Samuel Štancl 2025-10-29 19:24:06 +01:00
parent 0dc187510b
commit d274d8c902
No known key found for this signature in database
GPG key ID: BA146259A1E16C57
4 changed files with 13 additions and 33 deletions

View file

@ -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());
}

View file

@ -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'));