@@ -39,6 +39,7 @@ protected function setUp(): void
39
39
Schema::create ('tags ' , function (Blueprint $ table ) {
40
40
$ table ->increments ('id ' );
41
41
$ table ->string ('name ' );
42
+ $ table ->string ('type ' )->nullable ();
42
43
$ table ->timestamps ();
43
44
});
44
45
@@ -453,6 +454,18 @@ public function testUpdateOrCreateMethod()
453
454
$ this ->assertNotNull ($ post ->tags ()->whereName ('dives ' )->first ());
454
455
}
455
456
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
+
456
469
public function testSyncMethod ()
457
470
{
458
471
$ post = Post::create (['title ' => Str::random ()]);
@@ -647,7 +660,7 @@ public function testCanTouchRelatedModels()
647
660
648
661
public function testWherePivotOnString ()
649
662
{
650
- $ tag = Tag::create (['name ' => Str::random ()]);
663
+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
651
664
$ post = Post::create (['title ' => Str::random ()]);
652
665
653
666
DB ::table ('posts_tags ' )->insert ([
@@ -663,7 +676,7 @@ public function testWherePivotOnString()
663
676
664
677
public function testFirstWhere ()
665
678
{
666
- $ tag = Tag::create (['name ' => 'foo ' ]);
679
+ $ tag = Tag::create (['name ' => 'foo ' ])-> fresh () ;
667
680
$ post = Post::create (['title ' => Str::random ()]);
668
681
669
682
DB ::table ('posts_tags ' )->insert ([
@@ -679,7 +692,7 @@ public function testFirstWhere()
679
692
680
693
public function testWherePivotOnBoolean ()
681
694
{
682
- $ tag = Tag::create (['name ' => Str::random ()]);
695
+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
683
696
$ post = Post::create (['title ' => Str::random ()]);
684
697
685
698
DB ::table ('posts_tags ' )->insert ([
@@ -695,7 +708,7 @@ public function testWherePivotOnBoolean()
695
708
696
709
public function testWherePivotInMethod ()
697
710
{
698
- $ tag = Tag::create (['name ' => Str::random ()]);
711
+ $ tag = Tag::create (['name ' => Str::random ()])-> fresh () ;
699
712
$ post = Post::create (['title ' => Str::random ()]);
700
713
701
714
DB ::table ('posts_tags ' )->insert ([
@@ -730,7 +743,7 @@ public function testOrWherePivotInMethod()
730
743
public function testWherePivotNotInMethod ()
731
744
{
732
745
$ tag1 = Tag::create (['name ' => Str::random ()]);
733
- $ tag2 = Tag::create (['name ' => Str::random ()]);
746
+ $ tag2 = Tag::create (['name ' => Str::random ()])-> fresh () ;
734
747
$ post = Post::create (['title ' => Str::random ()]);
735
748
736
749
DB ::table ('posts_tags ' )->insert ([
@@ -768,7 +781,7 @@ public function testOrWherePivotNotInMethod()
768
781
public function testWherePivotNullMethod ()
769
782
{
770
783
$ tag1 = Tag::create (['name ' => Str::random ()]);
771
- $ tag2 = Tag::create (['name ' => Str::random ()]);
784
+ $ tag2 = Tag::create (['name ' => Str::random ()])-> fresh () ;
772
785
$ post = Post::create (['title ' => Str::random ()]);
773
786
774
787
DB ::table ('posts_tags ' )->insert ([
@@ -784,7 +797,7 @@ public function testWherePivotNullMethod()
784
797
785
798
public function testWherePivotNotNullMethod ()
786
799
{
787
- $ tag1 = Tag::create (['name ' => Str::random ()]);
800
+ $ tag1 = Tag::create (['name ' => Str::random ()])-> fresh () ;
788
801
$ tag2 = Tag::create (['name ' => Str::random ()]);
789
802
$ post = Post::create (['title ' => Str::random ()]);
790
803
@@ -909,8 +922,8 @@ public function testPivotDoesntHavePrimaryKey()
909
922
public function testOrderByPivotMethod ()
910
923
{
911
924
$ 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 () ;
914
927
$ tag4 = Tag::create (['name ' => Str::random ()]);
915
928
$ post = Post::create (['title ' => Str::random ()]);
916
929
@@ -1030,7 +1043,7 @@ class Tag extends Model
1030
1043
{
1031
1044
public $ table = 'tags ' ;
1032
1045
public $ timestamps = true ;
1033
- protected $ fillable = ['name ' ];
1046
+ protected $ fillable = ['name ' , ' type ' ];
1034
1047
1035
1048
public function posts ()
1036
1049
{
0 commit comments