File tree Expand file tree Collapse file tree 9 files changed +109
-2
lines changed
Expand file tree Collapse file tree 9 files changed +109
-2
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.8.0] - 2017-01-29
6+
7+ ### Added
8+
9+ - ` shouldApplyPublishedAtScope ` & ` shouldApplyPublishedFlagScope ` methods to skip Published flags global scope auto apply.
10+
511## [ 3.7.0] - 2017-01-14
612
713### Added
@@ -121,6 +127,7 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
121127
122128- ` is_active ` boolean flag added.
123129
130+ [ 3.8.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.7.0...3.8.0
124131[ 3.7.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.6.0...3.7.0
125132[ 3.6.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.5.0...3.6.0
126133[ 3.5.0 ] : https://github.com/cybercog/laravel-eloquent-flag/compare/3.4.0...3.5.0
Original file line number Diff line number Diff line change 5252 "docs" : " https://github.com/cybercog/laravel-eloquent-flag/wiki"
5353 },
5454 "require" : {
55- "illuminate/database" : " ~5.2.0|~5.3.0|~5.4.0 " ,
55+ "illuminate/database" : " ~5.2.0|~5.3.0" ,
5656 "php" : " ^5.6|^7.0"
5757 },
5858 "require-dev" : {
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ class PublishedAtScope implements Scope
3939 */
4040 public function apply (Builder $ builder , Model $ model )
4141 {
42+ if (method_exists ($ model , 'shouldApplyPublishedAtScope ' ) && !$ model ->shouldApplyPublishedAtScope ()) {
43+ return $ builder ;
44+ }
45+
4246 return $ builder ->whereNotNull ('published_at ' );
4347 }
4448
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ class PublishedFlagScope implements Scope
3838 */
3939 public function apply (Builder $ builder , Model $ model )
4040 {
41+ if (method_exists ($ model , 'shouldApplyPublishedFlagScope ' ) && !$ model ->shouldApplyPublishedFlagScope ()) {
42+ return $ builder ;
43+ }
44+
4145 return $ builder ->where ('is_published ' , 1 );
4246 }
4347
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ protected function destroyPackageMigrations()
7070 protected function migrateUnitTestTables ()
7171 {
7272 $ this ->artisan ('migrate ' , [
73- '--realpath ' => realpath ( __DIR__ . ' / database/migrations ') ,
73+ '--path ' => ' ../../../../tests/ database/migrations ' ,
7474 ]);
7575 }
7676
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 EntityWithPublishedAtUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Classic
18+ */
19+ class EntityWithPublishedAtUnapplied extends EntityWithPublishedAt
20+ {
21+ /**
22+ * Determine if PublishedAtScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyPublishedAtScope ()
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 EntityWithPublishedFlagUnapplied.
16+ *
17+ * @package Cog\Flag\Tests\Stubs\Models\Classic
18+ */
19+ class EntityWithPublishedFlagUnapplied extends EntityWithPublishedFlag
20+ {
21+ /**
22+ * Determine if PublishedFlagScope should be applied by default.
23+ *
24+ * @return bool
25+ */
26+ public function shouldApplyPublishedFlagScope ()
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 \EntityWithPublishedAt ;
16+ use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithPublishedAtUnapplied ;
1617use Cog \Flag \Tests \TestCase ;
1718
1819/**
@@ -109,4 +110,19 @@ public function it_can_unpublish_model()
109110
110111 $ this ->assertNull ($ model ->published_at );
111112 }
113+
114+ /** @test */
115+ public function it_can_skip_apply ()
116+ {
117+ factory (EntityWithPublishedAt::class, 3 )->create ([
118+ 'published_at ' => Carbon::now ()->subDay (),
119+ ]);
120+ factory (EntityWithPublishedAt::class, 2 )->create ([
121+ 'published_at ' => null ,
122+ ]);
123+
124+ $ entities = EntityWithPublishedAtUnapplied::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 \EntityWithPublishedFlag ;
15+ use Cog \Flag \Tests \Stubs \Models \Classic \EntityWithPublishedFlagUnapplied ;
1516use Cog \Flag \Tests \TestCase ;
1617
1718/**
@@ -108,4 +109,19 @@ public function it_can_unpublish_model()
108109
109110 $ this ->assertFalse ($ model ->is_published );
110111 }
112+
113+ /** @test */
114+ public function it_can_skip_apply ()
115+ {
116+ factory (EntityWithPublishedFlag::class, 3 )->create ([
117+ 'is_published ' => true ,
118+ ]);
119+ factory (EntityWithPublishedFlag::class, 2 )->create ([
120+ 'is_published ' => false ,
121+ ]);
122+
123+ $ entities = EntityWithPublishedFlagUnapplied::all ();
124+
125+ $ this ->assertCount (5 , $ entities );
126+ }
111127}
You can’t perform that action at this time.
0 commit comments