Skip to content

Commit cb1f5e1

Browse files
authored
Remove global scopes auto apply (#56)
Remove auto-apply global scopes by default
1 parent 6113d23 commit cb1f5e1

File tree

75 files changed

+2124
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2124
-211
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
77
### Added
88

99
- Laravel 5.8 support
10-
- Flag fields auto-casting
10+
- ([#48](https://github.com/cybercog/laravel-eloquent-flag/pull/48)) Flag fields auto-casting
11+
- Added `shouldApplyAcceptedAtScope` & `shouldApplyAcceptedFlagScope` methods to control Accepted flags global scope auto apply.
12+
- Added `shouldApplyActiveFlagScope` methods to control Active flag global scope auto apply.
13+
- Added `shouldApplyApprovedAtScope` & `shouldApplyApprovedFlagScope` methods to control Approved flags global scope auto apply.
14+
- Added `shouldApplyClosedAtScope` & `shouldApplyClosedFlagScope` methods to control Closed flags global scope auto apply.
1115

1216
### Changed
1317

@@ -87,7 +91,8 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
8791

8892
- Dropped PHP 5.6, 7.0 support
8993
- Dropped Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7 support
90-
- Removed attribute mutator `set*` & `unset*` methods from all helper classes
94+
- ([#50](https://github.com/cybercog/laravel-eloquent-flag/pull/50)) Removed attribute mutator `set*` & `unset*` methods from all helper classes
95+
- ([#56](https://github.com/cybercog/laravel-eloquent-flag/pull/56)) Removed global scopes auto-apply
9196

9297
## [4.0.0] - 2018-09-09
9398

src/Scopes/Classic/AcceptedAtScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ final class AcceptedAtScope implements Scope
4242
*/
4343
public function apply(Builder $builder, Model $model): void
4444
{
45-
$builder->whereNotNull('accepted_at');
45+
if (method_exists($model, 'shouldApplyAcceptedAtScope') && $model->shouldApplyAcceptedAtScope()) {
46+
$builder->whereNotNull('accepted_at');
47+
}
4648
}
4749

4850
/**

src/Scopes/Classic/AcceptedFlagScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ final class AcceptedFlagScope implements Scope
4141
*/
4242
public function apply(Builder $builder, Model $model): void
4343
{
44-
$builder->where('is_accepted', 1);
44+
if (method_exists($model, 'shouldApplyAcceptedFlagScope') && $model->shouldApplyAcceptedFlagScope()) {
45+
$builder->where('is_accepted', 1);
46+
}
4547
}
4648

4749
/**

src/Scopes/Classic/ActiveFlagScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ final class ActiveFlagScope implements Scope
4141
*/
4242
public function apply(Builder $builder, Model $model): void
4343
{
44-
$builder->where('is_active', 1);
44+
if (method_exists($model, 'shouldApplyActiveFlagScope') && $model->shouldApplyActiveFlagScope()) {
45+
$builder->where('is_active', 1);
46+
}
4547
}
4648

4749
/**

src/Scopes/Classic/ApprovedAtScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ final class ApprovedAtScope implements Scope
4242
*/
4343
public function apply(Builder $builder, Model $model): void
4444
{
45-
$builder->whereNotNull('approved_at');
45+
if (method_exists($model, 'shouldApplyApprovedAtScope') && $model->shouldApplyApprovedAtScope()) {
46+
$builder->whereNotNull('approved_at');
47+
}
4648
}
4749

4850
/**

src/Scopes/Classic/ApprovedFlagScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ final class ApprovedFlagScope implements Scope
4141
*/
4242
public function apply(Builder $builder, Model $model): void
4343
{
44-
$builder->where('is_approved', 1);
44+
if (method_exists($model, 'shouldApplyApprovedFlagScope') && $model->shouldApplyApprovedFlagScope()) {
45+
$builder->where('is_approved', 1);
46+
}
4547
}
4648

4749
/**

src/Scopes/Classic/InvitedAtScope.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ final class InvitedAtScope implements Scope
4242
*/
4343
public function apply(Builder $builder, Model $model): void
4444
{
45-
if (method_exists($model, 'shouldApplyInvitedAtScope') && !$model->shouldApplyInvitedAtScope()) {
46-
return;
45+
if (method_exists($model, 'shouldApplyInvitedAtScope') && $model->shouldApplyInvitedAtScope()) {
46+
$builder->whereNotNull('invited_at');
4747
}
48-
49-
$builder->whereNotNull('invited_at');
5048
}
5149

5250
/**

src/Scopes/Classic/InvitedFlagScope.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ final class InvitedFlagScope implements Scope
4141
*/
4242
public function apply(Builder $builder, Model $model): void
4343
{
44-
if (method_exists($model, 'shouldApplyInvitedFlagScope') && !$model->shouldApplyInvitedFlagScope()) {
45-
return;
44+
if (method_exists($model, 'shouldApplyInvitedFlagScope') && $model->shouldApplyInvitedFlagScope()) {
45+
$builder->where('is_invited', 1);
4646
}
47-
48-
$builder->where('is_invited', 1);
4947
}
5048

5149
/**

src/Scopes/Classic/KeptFlagScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ final class KeptFlagScope implements Scope
4141
*/
4242
public function apply(Builder $builder, Model $model): void
4343
{
44-
$builder->where('is_kept', 1);
44+
if (method_exists($model, 'shouldApplyKeptFlagScope') && $model->shouldApplyKeptFlagScope()) {
45+
$builder->where('is_kept', 1);
46+
}
4547
}
4648

4749
/**

src/Scopes/Classic/PublishedAtScope.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ final class PublishedAtScope implements Scope
4242
*/
4343
public function apply(Builder $builder, Model $model): void
4444
{
45-
if (method_exists($model, 'shouldApplyPublishedAtScope') && !$model->shouldApplyPublishedAtScope()) {
46-
return;
45+
if (method_exists($model, 'shouldApplyPublishedAtScope') && $model->shouldApplyPublishedAtScope()) {
46+
$builder->whereNotNull('published_at');
4747
}
48-
49-
$builder->whereNotNull('published_at');
5048
}
5149

5250
/**

0 commit comments

Comments
 (0)