/** * 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(); }
$response->write($json); return $response; })->add($authMiddleWare)->add($emptyParamMiddleware); // Update an emoji $app->put('/emojis/{id}', function ($request, $response, $args) { EmojiManager::updateEmoji($args['id'], $request->getParsedBody()); $message = ['success' => true, 'message' => 'Emoji successfully updated']; $response = $response->withHeader('Content-type', 'application/json'); $response = $response->withStatus(201); $json = json_encode($message); $response->write($json); return $response; })->add($authMiddleWare)->add($emptyParamMiddleware); // Partially update and emoji $app->patch('/emojis/{id}', function ($request, $response, $args) { $emoji = Emoji::find($args['id']); foreach ($request->getParsedBody() as $key => $value) { $emoji->{$key} = $value; } $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);