$date = $datos[$i]['value']; break; case "embedUrl": $embedUrl = $datos[$i]['value']; break; } } $vg = new Videogame(); $vg->name = $name; $vg->description = $desc; $vg->gamePlatform = $plataf; $vg->applicationSubCategory = $category; $vg->screenshot = $screenshot; $vg->datePublished = $date; $vg->embedUrl = $embedUrl; $vg->save(); // Mostramos la vista $app->render('videogame_template.php'); }); /* Modificar un videojuego en concreto */ $app->put('/videogames/:name', function ($name) use($app) { // Creamos un objeto collection + json con el videojuego pasada como parámetro // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos el videojuego de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $vg = \Videogame::find($name); //Código para peticiones de POST (creación de items) $body = $app->request->getBody(); $template = json_decode($body, true);
$embedUrl = $item['value']; break; case "datePublished": $datePublished = $item['value']; break; } } $new_videogame = new Videogame(); $new_videogame["name"] = $name; $new_videogame["description"] = $description; $new_videogame["gamePlatform"] = $gamePlatform; $new_videogame["applicationSubCategory"] = $applicationSubCategory; $new_videogame["screenshot"] = $screenshot; $new_videogame["embedUrl"] = $embedUrl; $new_videogame["datePublished"] = $datePublished; $new_videogame->save(); //falta sacar codigo 200 de sucess }); /* Update */ $app->put('/videogames/:id', function ($id) use($app) { $template = json_decode($app->request->getBody(), true); $datos = $template['template']['data']; $name; $description; $gamePlatform; $applicationSubCategory; $screenshot; $embedUrl; $datePublished; foreach ($datos as $item) { switch ($item['name']) {
$date = $datos[$i]['value']; break; case "embedUrl": $embedUrl = $datos[$i]['value']; break; } } $videogame = new Videogame(); $videogame->name = $name; $videogame->description = $desc; $videogame->gamePlatform = $plataf; $videogame->applicationSubCategory = $category; $videogame->screenshot = $screenshot; $videogame->datePublished = $date; $videogame->embedUrl = $embedUrl; $videogame->save(); // Mostramos la vista $app->render('videogame_template.php'); }); //Actualizar videojuego $app->put('/videogames/:id', function ($id) use($app) { // Creamos un objeto collection + json con el libro pasado como parámetro // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos el libro de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $nuevo_videogame = \VideoGame::find($id); $body = $app->request->getBody(); $template = json_decode($app->request->getBody(), true); $datos = $template['template']['data'];