File tree Expand file tree Collapse file tree 7 files changed +107
-0
lines changed
Expand file tree Collapse file tree 7 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 22
33All notable changes to ` laravel-eloquent-flag ` will be documented in this file.
44
5+ ## [ 3.10.0] - 2017-02-13
6+
7+ ### Added
8+
9+ - ` shouldApplyVerifiedAtScope ` & ` shouldApplyVerifiedFlagScope ` methods to skip Verified flags global scope auto apply.
10+
511## [ 3.9.0] - 2017-02-03
612
713### Added
@@ -133,6 +139,7 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
133139
134140- ` is_active ` boolean flag added.
135141
142+ [ 3.10.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.9.0...3.10.0
136143[ 3.9.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.8.0...3.9.0
137144[ 3.8.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.7.0...3.8.0
138145[ 3.7.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.6.0...3.7.0
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ class VerifiedAtScope implements Scope
3939 */
4040 public function apply (Builder $ builder , Model $ model )
4141 {
42+ if (method_exists ($ model , 'shouldApplyVerifiedAtScope ' ) && !$ model ->shouldApplyVerifiedAtScope ()) {
43+ return $ builder ;
44+ }
45+
4246 return $ builder ->whereNotNull ('verified_at ' );
4347 }
4448
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ class VerifiedFlagScope implements Scope
3838 */
3939 public function apply (Builder $ builder , Model $ model )
4040 {
41+ if (method_exists ($ model , 'shouldApplyVerifiedFlagScope ' ) && !$ model ->shouldApplyVerifiedFlagScope ()) {
42+ return $ builder ;
43+ }
44+
4145 return $ builder ->where ('is_verified ' , 1 );
4246 }
4347
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of Laravel Eloquent Flag.
5+ *
6+ * (c) Anton Komarev <a.komarev@cybercog.su>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Cog \Flag \Tests \Stubs \Models \Classic ;
13+
14+ /**
15+ * Class EntityWithVerifiedAtUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Classic
18+ */
19+ class EntityWithVerifiedAtUnapplied extends EntityWithVerifiedAt
20+ {
21+ /**
22+ * Determine if VerifiedAtScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyVerifiedAtScope ()
27+ {
28+ return false ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of Laravel Eloquent Flag.
5+ *
6+ * (c) Anton Komarev <a.komarev@cybercog.su>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Cog \Flag \Tests \Stubs \Models \Classic ;
13+
14+ /**
15+ * Class EntityWithVerifiedFlagUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Classic
18+ */
19+ class EntityWithVerifiedFlagUnapplied extends EntityWithVerifiedFlag
20+ {
21+ /**
22+ * Determine if VerifiedFlagScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyVerifiedFlagScope ()
27+ {
28+ return false ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1313
1414use Carbon \Carbon ;
1515use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithVerifiedAt ;
16+ use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithVerifiedAtUnapplied ;
1617use Cog \Flag \Tests \TestCase ;
1718
1819/**
@@ -109,4 +110,19 @@ public function it_can_unverify_model()
109110
110111 $ this ->assertNull ($ model ->verified_at );
111112 }
113+
114+ /** @test */
115+ public function it_can_skip_apply ()
116+ {
117+ factory (EntityWithVerifiedAt::class, 3 )->create ([
118+ 'verified_at ' => Carbon::now ()->subDay (),
119+ ]);
120+ factory (EntityWithVerifiedAt::class, 2 )->create ([
121+ 'verified_at ' => null ,
122+ ]);
123+
124+ $ entities = EntityWithVerifiedAtUnapplied::all ();
125+
126+ $ this ->assertCount (5 , $ entities );
127+ }
112128}
Original file line number Diff line number Diff line change 1212namespace Cog \Flag \Tests \Unit \Scopes \Classic ;
1313
1414use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithVerifiedFlag ;
15+ use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithVerifiedFlagUnapplied ;
1516use Cog \Flag \Tests \TestCase ;
1617
1718/**
@@ -108,4 +109,19 @@ public function it_can_unverify_model()
108109
109110 $ this ->assertFalse ($ model ->is_verified );
110111 }
112+
113+ /** @test */
114+ public function it_can_skip_apply ()
115+ {
116+ factory (EntityWithVerifiedFlag::class, 3 )->create ([
117+ 'is_verified ' => true ,
118+ ]);
119+ factory (EntityWithVerifiedFlag::class, 2 )->create ([
120+ 'is_verified ' => false ,
121+ ]);
122+
123+ $ entities = EntityWithVerifiedFlagUnapplied::all ();
124+
125+ $ this ->assertCount (5 , $ entities );
126+ }
111127}
You can’t perform that action at this time.
0 commit comments