gameDate()->associate(GameData::find($_POST['gameDataId'])); $vote->points += 1; if (!empty($_POST['comment'])) { $vote->comment = $_POST['comment']; } if (!$vote->save()) { http_response_code(500); } else { http_response_code(201); } } else { http_response_code(403); echo json_encode(["message" => "you have already voted"]); } } else { http_response_code(400); echo json_encode(["message" => "you have already voted"]); }