Ejemplo n.º 1
0
 /**
  * Update an existing emoji based on their id.
  *
  * @param int   $id   id of the emoji to be updated
  * @param array $data associative array of the emoji properties and updated values
  *
  * @return void
  */
 public static function updateEmoji($id, $data)
 {
     $emoji = Emoji::find($id);
     $emoji->name = $data['name'];
     $emoji->char = $data['char'];
     $emoji->keywords = $data['keywords'];
     $emoji->category = $data['category'];
     $emoji->date_modified = date('Y-m-d H:i:s');
     $emoji->save();
 }
Ejemplo n.º 2
0
    }
    $emoji->date_modified = date('Y-m-d H:i:s');
    $save = $emoji->save();
    if ($save) {
        $message = ['success' => true, 'message' => 'Emoji updated sucessfully'];
        $response = $response->withStatus(201);
    } else {
        $message = ['success' => false, 'message' => 'Emoji not partially updated'];
        $response = $response->withStatus(304);
    }
    $response = $response->withHeader('Content-type', 'application/json');
    $json = json_encode($message);
    $response->write($json);
    return $response;
})->add($authMiddleWare)->add($emptyParamMiddleware);
// Delete an emmoji
$app->delete('/emojis/{id}', function ($request, $response, $args) {
    $response = $response->withHeader('Content-type', 'application/json');
    $message = [];
    try {
        $del = Emoji::destroy($args['id']);
        $message = ['success' => true, 'message' => 'Emoji deleted successfully'];
        $response = $response->withStatus(200);
    } catch (Exception $e) {
        $message = ['success' => false, 'message' => "Could not delete emoji with id {$id}"];
        $response = $response->withStatus(404);
    }
    $json = json_encode($message);
    $response->write($json);
    return $response;
})->add($authMiddleWare);