Skip to content

Commit 9d78ca3

Browse files
author
Bill Harding
committed
Override withoutGlobalScopes
1 parent 01be319 commit 9d78ca3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/CacheKey.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ class CacheKey
1616
protected $macroKey;
1717
protected $model;
1818
protected $query;
19+
protected $withoutScopes = [];
20+
protected $withoutAllScopes = false;
1921

2022
public function __construct(
2123
array $eagerLoad,
2224
$model,
2325
$query,
24-
$macroKey
26+
$macroKey,
27+
$withoutScopes,
28+
$withoutAllScopes
2529
) {
2630
$this->eagerLoad = $eagerLoad;
2731
$this->macroKey = $macroKey;
2832
$this->model = $model;
2933
$this->query = $query;
34+
$this->withoutScopes = $withoutScopes;
35+
$this->withoutAllScopes = $withoutAllScopes;
3036
}
3137

3238
public function make(
@@ -57,6 +63,10 @@ protected function getBindingsSlug() : string
5763
return '';
5864
}
5965

66+
if ($this->withoutAllScopes || ($this->withoutScopes != null && count($this->withoutScopes) == 0)) {
67+
return Arr::query($this->model->query()->withoutGlobalScopes($this->withoutScopes)->getBindings());
68+
}
69+
6070
return Arr::query($this->model->query()->getBindings());
6171
}
6272

src/Traits/BuilderCaching.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ public function truncate()
2121

2222
return parent::truncate();
2323
}
24+
25+
public function withoutGlobalScopes(array $scopes = null)
26+
{
27+
$this->scopesAreApplied = true;
28+
$this->withoutScopes = $scopes;
29+
30+
if ($scopes == null || ($scopes != null && count($scopes) == 0)) {
31+
$this->withoutAllScopes = true;
32+
}
33+
34+
return parent::withoutGlobalScopes($scopes);
35+
}
2436
}

src/Traits/Caching.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ trait Caching
1616
protected $isCachable = true;
1717
protected $scopesAreApplied = false;
1818
protected $macroKey = "";
19+
protected $withoutScopes = null;
20+
protected $withoutAllScopes = false;
1921

2022
public function __call($method, $parameters)
2123
{
@@ -166,7 +168,7 @@ protected function makeCacheKey(
166168
$query = $this->query->getQuery();
167169
}
168170

169-
return (new CacheKey($eagerLoad, $model, $query, $this->macroKey))
171+
return (new CacheKey($eagerLoad, $model, $query, $this->macroKey, $this->withoutScopes, $this->withoutAllScopes))
170172
->make($columns, $idColumn, $keyDifferentiator);
171173
}
172174

0 commit comments

Comments
 (0)