/** * Update a user. * * @param $id * @return string|void */ public function update($id) { Csrf::checkToken($this->_request->getInput('_CSRF')); if ($this->_request->isAjax()) { $validator = new Validator($this->_request); $rules = ['password' => ['required', 'password'], 'password-repeat' => ['required']]; try { $this->_user = $this->_user->findOrFail($id); } catch (Exception $e) { return header('Location: ' . POST_REGISTER_URL); } $password = $this->_request->getInput('password'); $postData = $this->_request->getAllPostInput(); $this->_user->password = $this->_auth->hashPassword($password); if ($validator->validate($rules, $postData)) { if (!$this->_user->save()) { $response = ['status' => 'error']; return $this->_response->returnJson($response); } } $response = ['status' => 'success']; return $this->_response->returnJson($response); } return header('Location: ' . POST_REGISTER_URL); }
/** * Update a property. * * @param $id */ public function update($id) { try { $this->_property = $this->_property->findOrFail($id); } catch (Exception $e) { return header('Location: ' . POST_UPDATE_PROPERTY_URL); } Csrf::checkToken($this->_request->getInput('_CSRF')); $this->_pageData->csrfToken = Csrf::createToken(); $validator = new Validator($this->_request); $rules = ['name' => ['required']]; $name = $this->_request->getInput('name'); $rate = $this->_request->getInput('rate'); $short_desc = $this->_request->getRawInput('short_desc'); $long_desc = $this->_request->getRawInput('long_desc'); $postData = $this->_request->getAllPostInput(); if ($validator->validate($rules, $postData)) { $this->_property->name = $name; $this->_property->rate = $rate; $this->_property->short_Desc = $short_desc; $this->_property->long_Desc = $long_desc; if ($this->_property->save()) { return header('Location: ' . POST_ADD_PROPERTY_URL); } } $this->_pageData->pageTitle = "Edit Property"; $this->_pageData->loggedIn = $this->_auth->checkLoggedIn(); $this->_pageData->uri = $this->_request->getUri(); $this->_pageData->csrfToken = Csrf::createToken(); $this->_pageData->property = $this->_property; $this->_pageData->errors = $validator->getErrors(); return $this->_view->make('admin/edit-property', $this->_pageData); }
/** * Check availability of property. * * @return string */ public function check() { //Validate the input $validator = new Validator($this->_request); $rules = ['check_in' => ['required'], 'check_out' => ['required']]; $postData = $this->_request->getAllPostInput(); if (!$validator->validate($rules, $postData)) { $response = ['status' => 'error', 'errors' => $validator->getErrors()]; return $this->_response->returnJson($response); } $this->_reservation->pid = $postData['property']; $this->_reservation->check_in = date('Y-m-d', strtotime($this->_request->getInput("check_in"))); $this->_reservation->check_out = date('Y-m-d', strtotime($this->_request->getInput("check_out"))); $availability = new ReservationAvailability($this->_reservation); if (!$availability->check()) { $response = ['status' => 'unavailable']; return $this->_response->returnJson($response); } $response = ['status' => 'success']; return $this->_response->returnJson($response); }