/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $data = $request->only('name', 'price');
     try {
         $beverage = Beverage::find($id);
         $beverage->update($data);
         return $beverage;
     } catch (Exception $e) {
         return $e;
     }
 }
 public function getCommentsForBeverageJson($id)
 {
     $json = Beverage::getAllCommentsByBeverage($id);
     header('Content-type: application/json');
     return $json;
 }
 public static function getAllBeverages()
 {
     $conn = mysqli_connect(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'));
     if (!$conn) {
         die("Connection failed: " . mysqli_connect_error());
     }
     $sql = "SELECT throckmorton_finalproject.beverages.beverage_id, throckmorton_finalproject.beverages.beverage_name, throckmorton_finalproject.beverage_type.beverage_name AS beverage_type, AVG(throckmorton_finalproject.beverage_comments.rating) AS average_rating\n                FROM throckmorton_finalproject.beverages\n                LEFT JOIN throckmorton_finalproject.beverage_comments\n                ON throckmorton_finalproject.beverages.beverage_id=throckmorton_finalproject.beverage_comments.beverage_id\n                LEFT JOIN throckmorton_finalproject.beverage_type\n                ON throckmorton_finalproject.beverages.beverage_type=throckmorton_finalproject.beverage_type.beverage_id\n                GROUP BY throckmorton_finalproject.beverage_comments.beverage_id;";
     $result = mysqli_query($conn, $sql);
     $s = "[";
     //$s = "";
     $numRows = mysqli_num_rows($result);
     if ($numRows > 0) {
         for ($i = 0; $i < $numRows; $i++) {
             $row = mysqli_fetch_assoc($result);
             if (is_null($row["average_rating"])) {
                 $row["average_rating"] = "null";
             }
             $beverage = new Beverage($row["beverage_id"], $row["beverage_name"], $row["beverage_type"], $row["average_rating"]);
             $temp = $beverage->convertJson();
             $s .= $temp;
             if ($i < $numRows - 1) {
                 $s .= ", ";
             }
         }
     }
     $s .= "]";
     mysqli_close($conn);
     return $s;
 }