/** * @param array $data * @param $id * @return array * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function update(array $data, $id) { try { return $this->repository->update($data, $id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function update(array $data, $id) { try { $this->validator->with($data)->setId($id)->passesOrFail(); $this->repository->update($data, $id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { return $this->service->update($request->all(), $id); }
public function update(Request $request, $id, $noteId) { $this->repository->update($request->all(), $noteId); }
<?php include "../models/ClientRepository.php"; $config = (include "../db/config.php"); $db = new PDO($config["db"], $config["username"], $config["password"]); $clients = new ClientRepository($db); switch ($_SERVER["REQUEST_METHOD"]) { case "GET": $result = $clients->getAll(array(name => $_GET["name"], address => $_GET["address"], country_id => intval($_GET["country_id"]))); break; case "POST": $result = $clients->insert(array(name => $_POST["name"], age => intval($_POST["age"]), address => $_POST["address"], married => $_POST["married"] === "true" ? 1 : 0, country_id => intval($_POST["country_id"]))); break; case "PUT": parse_str(file_get_contents("php://input"), $_PUT); $result = $clients->update(array(id => intval($_PUT["id"]), name => $_PUT["name"], age => intval($_PUT["age"]), address => $_PUT["address"], married => $_PUT["married"] === "true" ? 1 : 0, country_id => intval($_PUT["country_id"]))); break; case "DELETE": parse_str(file_get_contents("php://input"), $_DELETE); $result = $clients->remove(intval($_DELETE["id"])); break; } header("Content-Type: application/json"); echo json_encode($result);