File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ public static function bootCachable()
2727 static ::deleted (function ($ instance ) {
2828 $ instance ->checkCooldownAndFlushAfterPersiting ($ instance );
2929 });
30+
3031 static ::saved (function ($ instance ) {
3132 $ instance ->checkCooldownAndFlushAfterPersiting ($ instance );
3233 });
Original file line number Diff line number Diff line change 1+ <?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration ;
2+
3+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
4+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
5+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
6+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
7+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
8+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedAuthor ;
9+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedBook ;
10+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedProfile ;
11+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedPublisher ;
12+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedStore ;
13+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Http \Resources \Author as AuthorResource ;
14+ use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
15+ use Illuminate \Foundation \Testing \RefreshDatabase ;
16+ use Illuminate \Support \Collection ;
17+
18+ class UpdateExistingPivotTest extends IntegrationTestCase
19+ {
20+ use RefreshDatabase;
21+
22+ public function testInRandomOrderCachesResults ()
23+ {
24+ $ book = (new Book )
25+ ->with ("stores " )
26+ ->whereHas ("stores " )
27+ ->first ();
28+ $ book ->stores ()
29+ ->updateExistingPivot (
30+ $ book ->stores ->first ()->id ,
31+ ["test " => "value " ]
32+ );
33+ $ updatedCount = (new Book )
34+ ->with ("stores " )
35+ ->whereHas ("stores " )
36+ ->first ()
37+ ->stores ()
38+ ->wherePivot ("test " , "value " )
39+ ->count ();
40+
41+ $ this ->assertEquals (1 , $ updatedCount );
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ public function up()
1313 $ table ->unsignedInteger ('store_id ' );
1414 $ table ->timestamps ();
1515
16+ $ table ->string ("test " )->nullable ();
17+
1618 $ table ->foreign ('book_id ' )
1719 ->references ('id ' )
1820 ->on ('books ' )
You can’t perform that action at this time.
0 commit comments