@@ -39,6 +39,7 @@ protected function setUp(): void
3939 Schema::create ('tags ' , function (Blueprint $ table ) {
4040 $ table ->increments ('id ' );
4141 $ table ->string ('name ' );
42+ $ table ->string ('type ' )->nullable ();
4243 $ table ->timestamps ();
4344 });
4445
@@ -453,6 +454,18 @@ public function testUpdateOrCreateMethod()
453454 $ this ->assertNotNull ($ post ->tags ()->whereName ('dives ' )->first ());
454455 }
455456
457+ public function testUpdateOrCreateMethodCreate ()
458+ {
459+ $ post = Post::create (['title ' => Str::random ()]);
460+
461+ $ post ->tags ()->updateOrCreate (['name ' => 'wavez ' ], ['type ' => 'featured ' ]);
462+
463+ $ tag = $ post ->tags ()->whereType ('featured ' )->first ();
464+
465+ $ this ->assertNotNull ($ tag );
466+ $ this ->assertSame ('wavez ' , $ tag ->name );
467+ }
468+
456469 public function testSyncMethod ()
457470 {
458471 $ post = Post::create (['title ' => Str::random ()]);
@@ -647,7 +660,7 @@ public function testCanTouchRelatedModels()
647660
648661 public function testWherePivotOnString ()
649662 {
650- $ tag = Tag::create (['name ' => Str::random ()]);
663+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
651664 $ post = Post::create (['title ' => Str::random ()]);
652665
653666 DB ::table ('posts_tags ' )->insert ([
@@ -663,7 +676,7 @@ public function testWherePivotOnString()
663676
664677 public function testFirstWhere ()
665678 {
666- $ tag = Tag::create (['name ' => 'foo ' ]);
679+ $ tag = Tag::create (['name ' => 'foo ' ])-> fresh () ;
667680 $ post = Post::create (['title ' => Str::random ()]);
668681
669682 DB ::table ('posts_tags ' )->insert ([
@@ -679,7 +692,7 @@ public function testFirstWhere()
679692
680693 public function testWherePivotOnBoolean ()
681694 {
682- $ tag = Tag::create (['name ' => Str::random ()]);
695+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
683696 $ post = Post::create (['title ' => Str::random ()]);
684697
685698 DB ::table ('posts_tags ' )->insert ([
@@ -695,7 +708,7 @@ public function testWherePivotOnBoolean()
695708
696709 public function testWherePivotInMethod ()
697710 {
698- $ tag = Tag::create (['name ' => Str::random ()]);
711+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
699712 $ post = Post::create (['title ' => Str::random ()]);
700713
701714 DB ::table ('posts_tags ' )->insert ([
@@ -730,7 +743,7 @@ public function testOrWherePivotInMethod()
730743 public function testWherePivotNotInMethod ()
731744 {
732745 $ tag1 = Tag::create (['name ' => Str::random ()]);
733- $ tag2 = Tag::create (['name ' => Str::random ()]);
746+ $ tag2 = Tag::create (['name ' => Str::random ()])-> fresh () ;
734747 $ post = Post::create (['title ' => Str::random ()]);
735748
736749 DB ::table ('posts_tags ' )->insert ([
@@ -768,7 +781,7 @@ public function testOrWherePivotNotInMethod()
768781 public function testWherePivotNullMethod ()
769782 {
770783 $ tag1 = Tag::create (['name ' => Str::random ()]);
771- $ tag2 = Tag::create (['name ' => Str::random ()]);
784+ $ tag2 = Tag::create (['name ' => Str::random ()])-> fresh () ;
772785 $ post = Post::create (['title ' => Str::random ()]);
773786
774787 DB ::table ('posts_tags ' )->insert ([
@@ -784,7 +797,7 @@ public function testWherePivotNullMethod()
784797
785798 public function testWherePivotNotNullMethod ()
786799 {
787- $ tag1 = Tag::create (['name ' => Str::random ()]);
800+ $ tag1 = Tag::create (['name ' => Str::random ()])-> fresh () ;
788801 $ tag2 = Tag::create (['name ' => Str::random ()]);
789802 $ post = Post::create (['title ' => Str::random ()]);
790803
@@ -909,8 +922,8 @@ public function testPivotDoesntHavePrimaryKey()
909922 public function testOrderByPivotMethod ()
910923 {
911924 $ tag1 = Tag::create (['name ' => Str::random ()]);
912- $ tag2 = Tag::create (['name ' => Str::random ()]);
913- $ tag3 = Tag::create (['name ' => Str::random ()]);
925+ $ tag2 = Tag::create (['name ' => Str::random ()])-> fresh () ;
926+ $ tag3 = Tag::create (['name ' => Str::random ()])-> fresh () ;
914927 $ tag4 = Tag::create (['name ' => Str::random ()]);
915928 $ post = Post::create (['title ' => Str::random ()]);
916929
@@ -1030,7 +1043,7 @@ class Tag extends Model
10301043{
10311044 public $ table = 'tags ' ;
10321045 public $ timestamps = true ;
1033- protected $ fillable = ['name ' ];
1046+ protected $ fillable = ['name ' , ' type ' ];
10341047
10351048 public function posts ()
10361049 {
0 commit comments