public function testPatchPosts() { $user = factory(User::class)->create(); $postObject = factory(Post::class)->create(['posted_by' => $user->id]); $postData = ['data' => ['type' => 'posts', 'attributes' => $postObject->toArray(), 'relationships' => ['posted_by' => ['data' => ['type' => 'users', 'id' => $user->id]]]]]; $postData['data']['attributes']['title'] = 'This is the new title'; $postData = json_encode($postData); $response = $this->callPatch(self::API_URL . $postObject->id, $postData); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); $this->assertNotNull($post = json_decode($response->getContent())->data); $this->assertNotEmpty($post->id); // test to make sure the user was created $updatedPost = Post::findOrFail($post->id); $this->assertEquals('This is the new title', $updatedPost->title); }
public function destroy(Post $posts) { $posts->delete(); return response()->json('', Response::HTTP_NO_CONTENT); }