2020namespace App \Tests \Api \V1 ;
2121
2222use App \Models \Post ;
23+ use App \Models \Tag ;
2324use App \Models \User ;
2425use LaravelJsonApi \Core \Document \ResourceObject ;
2526use function url ;
@@ -42,11 +43,12 @@ public function post(Post $post): ResourceObject
4243 'id ' => (string ) $ post ->getRouteKey (),
4344 'attributes ' => [
4445 'content ' => $ post ->content ,
45- 'createdAt ' => $ post ->created_at ->toJSON (),
46+ 'createdAt ' => $ post ->created_at ->jsonSerialize (),
47+ 'publishedAt ' => optional ($ post ->published_at )->jsonSerialize (),
4648 'slug ' => $ post ->slug ,
4749 'synopsis ' => $ post ->synopsis ,
4850 'title ' => $ post ->title ,
49- 'updatedAt ' => $ post ->updated_at ->toJSON (),
51+ 'updatedAt ' => $ post ->updated_at ->jsonSerialize (),
5052 ],
5153 'relationships ' => [
5254 'author ' => [
@@ -74,6 +76,41 @@ public function post(Post $post): ResourceObject
7476 ]);
7577 }
7678
79+ /**
80+ * Get the expected tag resource.
81+ *
82+ * @param Tag $tag
83+ * @return ResourceObject
84+ */
85+ public function tag (Tag $ tag ): ResourceObject
86+ {
87+ $ self = url ('/api/v1/tags ' , $ tag );
88+
89+ return ResourceObject::fromArray ([
90+ 'type ' => 'tags ' ,
91+ 'id ' => (string ) $ tag ->getRouteKey (),
92+ 'attributes ' => [
93+ 'createdAt ' => $ tag ->created_at ->jsonSerialize (),
94+ 'name ' => $ tag ->name ,
95+ 'updatedAt ' => $ tag ->updated_at ->jsonSerialize (),
96+ ],
97+ 'relationships ' => [
98+ 'posts ' => [
99+ 'links ' => [
100+ 'self ' => "{$ self }/relationships/posts " ,
101+ 'related ' => "{$ self }/posts " ,
102+ ],
103+ ],
104+ 'videos ' => [
105+ 'links ' => [
106+ 'self ' => "{$ self }/relationships/videos " ,
107+ 'related ' => "{$ self }/videos " ,
108+ ],
109+ ],
110+ ],
111+ ]);
112+ }
113+
77114 /**
78115 * Get the expected user resource.
79116 *
@@ -88,9 +125,9 @@ public function user(User $user): ResourceObject
88125 'type ' => 'users ' ,
89126 'id ' => (string ) $ user ->getRouteKey (),
90127 'attributes ' => [
91- 'createdAt ' => $ user ->created_at ->toJSON (),
128+ 'createdAt ' => $ user ->created_at ->jsonSerialize (),
92129 'name ' => $ user ->name ,
93- 'updatedAt ' => $ user ->updated_at ->toJSON (),
130+ 'updatedAt ' => $ user ->updated_at ->jsonSerialize (),
94131 ],
95132 'links ' => [
96133 'self ' => $ self ,
0 commit comments