public function borrar_telefono() { $id = Input::get('idedit'); $telefono = Phone::find($id); if ($telefono->delete()) { Session::flash('message', 'Eliminado correctamente'); Session::flash('class', 'success'); } else { Session::flash('message', 'Ha ocurrido un error, intentelo nuevamente'); Session::flash('class', 'danger'); } return Redirect::to('telefono'); }
/** * Update (basically create new one but with provided id) mine phone * This functions requires token - user must validate phone number via sms * @param $id * * @return Response */ public function selfUpdatePhone($id) { $token = Input::get('token'); $smsEntry = SMS::where('token', $token)->orderBy('id')->first(); if (!$smsEntry) { return $this->respondInsufficientPrivileges('user.invalid-token'); } if (!$smsEntry->verified) { return Response::json(['error' => ['message' => 'Your number is not yet verified. Please re-register', 'status' => 1]], 403); } $phone = Phone::find($id); if (!$phone) { return $this->respondNotFound('user.phone-not-found'); } $phone->fill(['number' => $smsEntry->phone]); if ($phone->save()) { $smsEntry->delete(); // $user = Auth::user(); return $this->respond($phone); // return $user->phones; } return $this->respondNotFound('user.phone-not-found'); }
$contactList->put("/phones/:id", function ($id) use($contactList) { $phone = $contactList->request->params('phone'); $editPhone = Phone::find($id); $editPhone->phone = $phone; if ($editPhone->save()) { $data['msg'] = 'Phone saved successfully!'; $data['id'] = $editPhone->id; } else { $data['msg'] = 'An error occurred while saving the phone!'; } $contactList->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); // Delete phone $contactList->delete("/phones/:id", function ($id) use($contactList) { $phone = Phone::find($id); if ($phone->delete()) { $data['msg'] = 'Phone deleted successfully!'; } else { $data['msg'] = 'An error occurred while deleting the phone!'; } $contactList->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); // Get all address to one contact $contactList->get("/contact/:id/address", function ($id) use($contactList) { $addresses = Address::where('contactId', '=', $id)->get(); $contactList->response()->header('Content-Type', 'application/json'); echo json_encode(objectToArray(json_decode($addresses))); }); // Add new address