/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // retrieve category $comment = Comment::find($id); // check exists if (empty($comment)) { return response()->json(null, 404); } // check self comment if ($comment->user_id != Auth::user()->id) { return response()->json(null, 403); } if (!$comment->delete()) { return response()->json(null, 500); // @codeCoverageIgnore } return response()->json(null, 204); }
public function testDeleteSuccess() { $user = factory(App\User::class)->create(); Auth::login($user); $comment = factory(Comment::class)->create(['user_id' => $user->id]); $res = $this->call('DELETE', "/comments/{$comment->id}"); $this->assertEquals(204, $res->getStatusCode()); $exists = Comment::find($comment->id); $this->assertNull($exists); }