when(! config('tenancy.pending.include_in_queries'), function (Builder $builder) { $builder->whereNull('data->pending_since'); }); } /** * Extend the query builder with the needed functions. * * @return void */ public function extend(Builder $builder) { foreach ($this->extensions as $extension) { $this->{"add{$extension}"}($builder); } } /** * Add the with-pending extension to the builder. * * @return void */ protected function addWithPending(Builder $builder) { $builder->macro('withPending', function (Builder $builder, $withPending = true) { if (! $withPending) { return $builder->withoutPending(); } return $builder->withoutGlobalScope($this); }); } /** * Add the without-pending extension to the builder. * * @return void */ protected function addWithoutPending(Builder $builder) { $builder->macro('withoutPending', function (Builder $builder) { $builder->withoutGlobalScope($this) ->whereNull('data->pending_since') ->orWhereNull('data'); return $builder; }); } /** * Add the only-pending extension to the builder. * * @return void */ protected function addOnlyPending(Builder $builder) { $builder->macro('onlyPending', function (Builder $builder) { $builder->withoutGlobalScope($this)->whereNotNull('data->pending_since'); return $builder; }); } }