/** * Edit page * * @param $id * @param array $data * @return mixed * @throws Exception */ public function edit($id, array $data) { $post = $this->post->findById($id); if (!$post && $post['type'] == 1) { throw new Exception('Your provided post id does not return data.'); } $post = $this->post->updateById($id, ['title' => $data['title'], 'slug' => $data['slug'], 'content' => $data['content'], 'menu' => (int) $data['menu'] == 1 ? 1 : 0]); return $post; }
/** * Update post * * @param $id * @param array $data * @return mixed * @throws NotFoundException */ public function edit($id, array $data) { $post = $this->getPostById($id); $post = $this->post->updateById($id, ['title' => $data['title'], 'slug' => $data['slug'], 'preview' => $data['preview'], 'content' => $data['content'], 'menu' => (int) $data['menu'] == 1 ? 1 : 0]); /** Detach an retach process */ $this->post->detachFromAll($id); $data['categories'] = isset($data['categories']) ? (array) $data['categories'] : []; foreach ($data['categories'] as $category) { $this->post->attachToCategory($id, $category); } return $post; }