Skip to content

Commit

Permalink
Remove ability to exclude global scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
one2tek-ak committed Dec 10, 2021
1 parent 65634c0 commit 876d510
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 42 deletions.
1 change: 0 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- Scopes
- [Quick start](scopes.md?id=scopes)
- [Usage](scopes.md?id=usage)
- [Remove Global Scopes](scopes.md?id=remove-global-scopes)

- Appends
- [Quick start](appends.md?id=appends)
Expand Down
11 changes: 0 additions & 11 deletions docs/scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,4 @@ The following query parameter will add the `popular` scope:

```url
{base_url}/users?scope[]=popular
```

# Remove Global Scopes

Global scopes allow you to add constraints to all queries for a given model.
What if we want to remove it ?

The following query parameter will remove the `delivered` global scope:

```url
{base_url}/books?excludeGlobalScopes[]=delivered
```
21 changes: 0 additions & 21 deletions src/Controllers/LaravelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,6 @@ protected function parseWithCount(array $withCounts)
return $return;
}

/**
* Parse excludeGlobalScopes into resource.
*
* @param array $excludeGlobalScopes
*
* @return array
*/
protected function parseExcludeGlobalScopes(array $excludeGlobalScopes)
{
$return = [];

foreach ($excludeGlobalScopes as $exludeGlobalScope) {
$return[] = $exludeGlobalScope;
}

return $return;
}

/**
* Parse filters.
*
Expand Down Expand Up @@ -367,7 +349,6 @@ protected function parseResourceOptions($request = null)
'withs' => [],
'has' => [],
'doesntHave' => [],
'excludeGlobalScopes' => [],
'scope' => [],
'sort' => [],
'limit' => null,
Expand All @@ -392,7 +373,6 @@ protected function parseResourceOptions($request = null)
$withs = $request->get('with', $this->defaults['withs']);
$has = $request->get('has', $this->defaults['has']);
$doesntHave = $request->get('doesntHave', $this->defaults['doesntHave']);
$excludeGlobalScopes = $this->parseExcludeGlobalScopes($request->get('excludeGlobalScopes', $this->defaults['excludeGlobalScopes']));
$scope = $request->get('scope', $this->defaults['scope']);
$sort = $this->parseSort($request->get('sort', $this->defaults['sort']));
$limit = $request->get('limit', $this->defaults['limit']);
Expand All @@ -415,7 +395,6 @@ protected function parseResourceOptions($request = null)
'withs' => $withs,
'has' => $has,
'doesntHave' => $doesntHave,
'excludeGlobalScopes' => $excludeGlobalScopes,
'modes' => $modes,
'scope' => $scope,
'sort' => $sort,
Expand Down
9 changes: 0 additions & 9 deletions src/Database/EloquentBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ protected function applyResourceOptions(Builder $queryBuilder, array $options =
}
}

if (isset($excludeGlobalScopes)) {
$this->applyWithouGlobalScopes($queryBuilder, $excludeGlobalScopes);
}

if (isset($filter_groups)) {
$this->applyFilterGroups($queryBuilder, $filter_groups);
}
Expand Down Expand Up @@ -158,11 +154,6 @@ protected function applySortByDesc(Builder $queryBuilder, array $sortByDesc = []
}
}

protected function applyWithouGlobalScopes(Builder $queryBuilder, array $excludeGlobalScopes = [])
{
$queryBuilder->withoutGlobalScopes($excludeGlobalScopes);
}

protected function applyFilter(Builder $queryBuilder, array $filter, $or = false)
{
$column = $filter['column'];
Expand Down

0 comments on commit 876d510

Please sign in to comment.