Skip to content

Commit c6e8785

Browse files
author
Bill Harding
committed
Move withoutGlobalScopes to BuilderCaching
1 parent a28c0bf commit c6e8785

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/Traits/BuilderCaching.php

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

2222
return parent::truncate();
2323
}
24+
25+
public function withoutGlobalScope($scope)
26+
{
27+
if ($this->withoutScopes == null) {
28+
$this->withoutScopes = [];
29+
}
30+
31+
array_push($this->withoutScopes, $scope);
32+
33+
return parent::withoutGlobalScope($scope);
34+
}
35+
36+
public function withoutGlobalScopes(array $scopes = null)
37+
{
38+
$this->withoutScopes = $scopes;
39+
40+
if ($scopes == null || ($scopes != null && count($scopes) == 0)) {
41+
$this->withoutAllScopes = true;
42+
}
43+
44+
return parent::withoutGlobalScopes($scopes);
45+
}
46+
2447
}

src/Traits/Caching.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,17 @@ public function applyScopes()
4343
return parent::applyScopes();
4444
}
4545

46-
public function withoutGlobalScope($scope)
47-
{
48-
$this->scopesAreApplied = true;
49-
if ($this->withoutScopes == null) {
50-
$this->withoutScopes = [];
51-
}
52-
53-
array_push($this->withoutScopes[], $scope);
54-
$this->withoutAllScopes = false;
55-
56-
return parent::withoutGlobalScope($scope);
57-
}
58-
59-
public function withoutGlobalScopes(array $scopes = null)
60-
{
61-
$this->scopesAreApplied = true;
62-
$this->withoutScopes = $scopes;
63-
64-
if ($scopes == null || ($scopes != null && count($scopes) == 0)) {
65-
$this->withoutAllScopes = true;
66-
}
67-
68-
return parent::withoutGlobalScopes($scopes);
69-
}
70-
7146
protected function applyScopesToInstance()
7247
{
7348
if (! property_exists($this, "scopes")
7449
|| $this->scopesAreApplied
50+
|| $this->withoutAllScopes
7551
) {
7652
return;
7753
}
7854

7955
foreach ($this->scopes as $identifier => $scope) {
80-
if (! isset($this->scopes[$identifier])) {
56+
if (! isset($this->scopes[$identifier]) || isset($this->withoutScopes[$identifier])) {
8157
continue;
8258
}
8359

0 commit comments

Comments
 (0)