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.9.0] - 2017-02-03
6+
7+ ### Added
8+
9+ - ` shouldApplyExpiredAtScope ` & ` shouldApplyExpiredFlagScope ` methods to skip Expired flags global scope auto apply.
10+
511## [ 3.8.0] - 2017-01-29
612
713### Added
@@ -127,6 +133,7 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
127133
128134- ` is_active ` boolean flag added.
129135
136+ [ 3.9.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.8.0...3.9.0
130137[ 3.8.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.7.0...3.8.0
131138[ 3.7.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.6.0...3.7.0
132139[ 3.6.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.5.0...3.6.0
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ class ExpiredAtScope implements Scope
3939 */
4040 public function apply (Builder $ builder , Model $ model )
4141 {
42+ if (method_exists ($ model , 'shouldApplyExpiredAtScope ' ) && !$ model ->shouldApplyExpiredAtScope ()) {
43+ return $ builder ;
44+ }
45+
4246 return $ builder ->whereNull ('expired_at ' );
4347 }
4448
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ class ExpiredFlagScope implements Scope
3838 */
3939 public function apply (Builder $ builder , Model $ model )
4040 {
41+ if (method_exists ($ model , 'shouldApplyExpiredFlagScope ' ) && !$ model ->shouldApplyExpiredFlagScope ()) {
42+ return $ builder ;
43+ }
44+
4145 return $ builder ->where ('is_expired ' , 0 );
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 \Inverse ;
13+
14+ /**
15+ * Class EntityWithExpiredAtUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Inverse
18+ */
19+ class EntityWithExpiredAtUnapplied extends EntityWithExpiredAt
20+ {
21+ /**
22+ * Determine if ExpiredAtScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyExpiredAtScope ()
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 \Inverse ;
13+
14+ /**
15+ * Class EntityWithExpiredFlagUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Inverse
18+ */
19+ class EntityWithExpiredFlagUnapplied extends EntityWithExpiredFlag
20+ {
21+ /**
22+ * Determine if ExpiredFlagScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyExpiredFlagScope ()
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 \Inverse \EntityWithExpiredAt ;
16+ use Cog \Flag \Tests \Stubs \Models \Inverse \EntityWithExpiredAtUnapplied ;
1617use Cog \Flag \Tests \TestCase ;
1718
1819/**
@@ -109,4 +110,19 @@ public function it_can_expire_model()
109110
110111 $ this ->assertNotNull ($ model ->expired_at );
111112 }
113+
114+ /** @test */
115+ public function it_can_skip_apply ()
116+ {
117+ factory (EntityWithExpiredAt::class, 3 )->create ([
118+ 'expired_at ' => Carbon::now ()->subDay (),
119+ ]);
120+ factory (EntityWithExpiredAt::class, 2 )->create ([
121+ 'expired_at ' => null ,
122+ ]);
123+
124+ $ entities = EntityWithExpiredAtUnapplied::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 \Inverse ;
1313
1414use Cog \Flag \Tests \Stubs \Models \Inverse \EntityWithExpiredFlag ;
15+ use Cog \Flag \Tests \Stubs \Models \Inverse \EntityWithExpiredFlagUnapplied ;
1516use Cog \Flag \Tests \TestCase ;
1617
1718/**
@@ -108,4 +109,19 @@ public function it_can_expire_model()
108109
109110 $ this ->assertTrue ($ model ->is_expired );
110111 }
112+
113+ /** @test */
114+ public function it_can_skip_apply ()
115+ {
116+ factory (EntityWithExpiredFlag::class, 3 )->create ([
117+ 'is_expired ' => true ,
118+ ]);
119+ factory (EntityWithExpiredFlag::class, 2 )->create ([
120+ 'is_expired ' => false ,
121+ ]);
122+
123+ $ entities = EntityWithExpiredFlagUnapplied::all ();
124+
125+ $ this ->assertCount (5 , $ entities );
126+ }
111127}
You can’t perform that action at this time.
0 commit comments