Skip to content

Commit

Permalink
fixes softDeletes with applying scopes ref #226
Browse files Browse the repository at this point in the history
  • Loading branch information
raftx24 committed Dec 8, 2020
1 parent f2537a6 commit 83a8a54
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/Services/Data/Builders/Meta.php
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config as ConfigFacade;
use LaravelEnso\Companies\Models\Company;
use LaravelEnso\Tables\Contracts\CustomCount;
use LaravelEnso\Tables\Contracts\CustomCountCacheKey;
use LaravelEnso\Tables\Contracts\Table;
Expand Down Expand Up @@ -67,9 +68,9 @@ public function count($filtered = false): int
}

return $this->query
->when($this->config->get('softDeletes'), fn ($query) => $query
->whereNull($this->deletedAt()))
->getQuery()->getCountForPagination();
->applyScopes()
->getQuery()
->getCountForPagination();
}

public function filter(): self
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Data/Config.php
Expand Up @@ -12,7 +12,7 @@ class Config
{
private const TemplateProxy = [
'appends', 'comparisonOperator', 'countCache', 'flatten', 'fullInfoRecordLimit',
'name', 'strip', 'softDeletes', 'table',
'name', 'strip', 'table',
];

private const RequestMeta = [
Expand Down
12 changes: 1 addition & 11 deletions src/Services/Template.php
Expand Up @@ -3,7 +3,6 @@
namespace LaravelEnso\Tables\Services;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
Expand Down Expand Up @@ -101,8 +100,7 @@ private function template()
$this->setModel($template, $model);
}

$this->setTable($template, $model)
->setSoftDeletes($template, $model);
$this->setTable($template, $model);

return $template;
}
Expand All @@ -121,14 +119,6 @@ private function setTable(Obj $template, Model $model): self
return $this;
}

private function setSoftDeletes(Obj $template, Model $model)
{
$traits = (new ReflectionClass($model))->getTraitNames();
$template->set('softDeletes', in_array(SoftDeletes::class, $traits));

return $this;
}

private function readJson($path)
{
$template = new Obj(
Expand Down

0 comments on commit 83a8a54

Please sign in to comment.