@@ -80,4 +80,37 @@ public function it_can_do_inline_contraints_as_well()
80
80
$ this ->assertFalse ($ posts ->get (2 )->title_is_foo_and_has_six_comments_or_more );
81
81
$ this ->assertFalse ($ posts ->get (3 )->title_is_foo_and_has_six_comments_or_more );
82
82
}
83
+
84
+ /** @test */
85
+ public function it_can_mix_scopes_outside_of_the_closure ()
86
+ {
87
+ $ postA = Post::create (['title ' => 'foo ' ]);
88
+ $ postB = Post::create (['title ' => 'foo ' ]);
89
+ $ postC = Post::create (['title ' => 'bar ' ]);
90
+ $ postD = Post::create (['title ' => 'bar ' ]);
91
+
92
+ foreach (range (1 , 5 ) as $ i ) {
93
+ $ postA ->comments ()->create (['body ' => 'ok ' ]);
94
+ $ postC ->comments ()->create (['body ' => 'ok ' ]);
95
+ }
96
+
97
+ foreach (range (1 , 10 ) as $ i ) {
98
+ $ postB ->comments ()->create (['body ' => 'ok ' ]);
99
+ $ postD ->comments ()->create (['body ' => 'ok ' ]);
100
+ }
101
+
102
+ $ posts = Post::query ()
103
+ ->where ('title ' , 'foo ' )
104
+ ->addScopeAsSelect ('title_is_foo_and_has_six_comments_or_more ' , function ($ query ) {
105
+ $ query ->has ('comments ' , '>= ' , 6 );
106
+ })
107
+ ->orderBy ('id ' )
108
+ ->get ();
109
+
110
+ $ this ->assertCount (2 , $ posts );
111
+ $ this ->assertTrue ($ posts ->contains ($ postA ));
112
+ $ this ->assertTrue ($ posts ->contains ($ postB ));
113
+ $ this ->assertFalse ($ posts ->get (0 )->title_is_foo_and_has_six_comments_or_more );
114
+ $ this ->assertTrue ($ posts ->get (1 )->title_is_foo_and_has_six_comments_or_more );
115
+ }
83
116
}
0 commit comments