File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ public function fields(): array
75
75
DateTime::make ('publishedAt ' )->sortable (),
76
76
Str::make ('slug ' ),
77
77
Str::make ('synopsis ' ),
78
- BelongsToMany::make ('tags ' ),
78
+ BelongsToMany::make ('tags ' )-> mustValidate () ,
79
79
Str::make ('title ' )->sortable (),
80
80
DateTime::make ('updatedAt ' )->sortable ()->readOnly (),
81
81
];
Original file line number Diff line number Diff line change @@ -45,10 +45,16 @@ protected function setUp(): void
45
45
46
46
public function test (): void
47
47
{
48
- $ tag = Tag::factory ()->create ();
49
- $ this ->post ->tags ()->attach ($ tag );
48
+ $ this ->post ->tags ()->saveMany (
49
+ Tag::factory ()->count (2 )->create ()
50
+ );
51
+
52
+ $ tags = Tag::factory ()->count (1 )->create ();
53
+
54
+ $ data = $ this
55
+ ->serialize ()
56
+ ->replace ('tags ' , $ this ->identifiersFor ('tags ' , $ tags ));
50
57
51
- $ data = $ this ->serialize ();
52
58
$ expected = $ data ->forget ('updatedAt ' )->jsonSerialize ();
53
59
54
60
$ response = $ this
@@ -69,6 +75,16 @@ public function test(): void
69
75
'synopsis ' => $ data ['synopsis ' ],
70
76
'title ' => $ data ['title ' ],
71
77
]);
78
+
79
+ $ this ->assertDatabaseCount ('taggables ' , count ($ tags ));
80
+
81
+ foreach ($ tags as $ tag ) {
82
+ $ this ->assertDatabaseHas ('taggables ' , [
83
+ 'tag_id ' => $ tag ->getKey (),
84
+ 'taggable_type ' => Post::class,
85
+ 'taggable_id ' => $ this ->post ->getKey (),
86
+ ]);
87
+ }
72
88
}
73
89
74
90
/**
You can’t perform that action at this time.
0 commit comments