@@ -2718,6 +2718,45 @@ public function testCanFillAndInsertIntoHasManyRelationship()
2718
2718
$ this ->assertEquals (Carbon::parse ('2025-02-24T15:16:55.000Z ' ), $ user ->posts ->find (3 )->published_at );
2719
2719
}
2720
2720
2721
+ public function testFillAndInsertOrIgnoreIntoHasManyRelationship ()
2722
+ {
2723
+ Str::createUuidsUsingSequence ([
2724
+ '00000000-0000-7000-0000-000000000000 ' , // user
2725
+ '11111111-1111-1111-1111-111111111111 ' , // post id=1
2726
+ '22222222-2222-2222-2222-222222222222 ' , // post id=1 ignored
2727
+ '33333333-3333-3333-3333-333333333333 ' , // post id=3
2728
+ ]);
2729
+
2730
+ $ user = tap (new UserWithUniqueStringIds (), function ($ user ) {
2731
+ $ user ->forceFill (['name ' => 'Taylor Otwell ' ])->save ();
2732
+ });
2733
+
2734
+ $ attributes = [
2735
+ ['id ' => 1 , 'published_at ' => now (), 'name ' => 'ship of die ' ],
2736
+ ['id ' => 3 , 'published_at ' => now (), 'name ' => 'Welcome to the future of Laravel ' ],
2737
+ ];
2738
+
2739
+ $ this ->assertSame (1 , $ user ->posts ()->fillAndInsertOrIgnore (array_slice ($ attributes , 0 , 1 )));
2740
+ $ this ->assertSame (1 , $ user ->posts ()->fillAndInsertOrIgnore (array_slice ($ attributes , 0 , 2 )));
2741
+
2742
+ $ this ->assertSame ('11111111-1111-1111-1111-111111111111 ' , $ user ->posts ->find (1 )->uuid );
2743
+ $ this ->assertSame ('33333333-3333-3333-3333-333333333333 ' , $ user ->posts ->find (3 )->uuid );
2744
+ }
2745
+
2746
+ public function testfillAndInsertGetIdIntoHasManyRelationship ()
2747
+ {
2748
+ $ user = tap (new UserWithUniqueStringIds (), function ($ user ) {
2749
+ $ user ->forceFill (['name ' => 'Taylor Otwell ' ])->save ();
2750
+ });
2751
+
2752
+ $ id = $ user ->posts ()->fillAndInsertGetId ([
2753
+ 'name ' => 'We must ship. ' ,
2754
+ 'published_at ' => now (),
2755
+ ]);
2756
+
2757
+ $ this ->assertSame (1 , $ id );
2758
+ }
2759
+
2721
2760
/**
2722
2761
* Helpers...
2723
2762
*/
0 commit comments