File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,25 @@ public function testBelongsToManyAttachesExistingModels()
258
258
$ this ->assertStringStartsWith ('synced ' , $ user ->clients [1 ]->name );
259
259
}
260
260
261
+ public function testBelongsToManySync ()
262
+ {
263
+ // create test instances
264
+ $ user = User::create (array ('name ' => 'John Doe ' ));
265
+ $ client1 = Client::create (array ('name ' => 'Pork Pies Ltd. ' ))->_id ;
266
+ $ client2 = Client::create (array ('name ' => 'Buffet Bar Inc. ' ))->_id ;
267
+
268
+ // Sync multiple
269
+ $ user ->clients ()->sync (array ($ client1 , $ client2 ));
270
+ $ this ->assertCount (2 , $ user ->clients );
271
+
272
+ // Refresh user
273
+ $ user = User::where ('name ' , '= ' , 'John Doe ' )->first ();
274
+
275
+ // Sync single
276
+ $ user ->clients ()->sync (array ($ client1 ));
277
+ $ this ->assertCount (1 , $ user ->clients );
278
+ }
279
+
261
280
public function testBelongsToManyCustom ()
262
281
{
263
282
$ user = User::create (array ('name ' => 'John Doe ' ));
You can’t perform that action at this time.
0 commit comments