/**
  * list of post
  *
  * @param array $filter
  *
  * @return array
  */
 public function all($filter = [])
 {
     if (array_has($filter, "category")) {
         $category = $this->category->find($filter['category']);
         $category_ids = $category->getDescendantsAndSelf()->lists('id')->toArray();
         $posts = $this->postRepo->getByCategoryId($category_ids, true);
     } elseif (array_has($filter, "tag")) {
         $posts = $this->postRepo->getByTags($filter['tag'], true);
     } elseif (array_has($filter, "query")) {
         $posts = $this->postRepo->search($filter['query'], true);
     } else {
         $posts = $this->postRepo->all($filter);
     }
     $postArray = [];
     foreach ($posts as $post) {
         $postArray[] = $this->formatPost($post);
     }
     $posts = $posts->toArray();
     $response = array_except($posts, 'data');
     $response['data'] = $postArray;
     return $response;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int             $id
  * @param  CategoryRequest $request
  * @return Response
  */
 public function update($id, CategoryRequest $request)
 {
     $category = $this->category->find($id);
     $formData = $request->all();
     if ($category->isRoot()) {
         $formData['parent_id'] = null;
     }
     if ($this->category->update($id, $formData)) {
         if ($category->isRoot()) {
             return redirect()->route('category.index')->with('success', 'Category updated successfully.');
         }
         $root = $category->getRoot();
         $parent_id = $root->id;
         $active_id = $id;
         if ($category->getDepth() > 1) {
             $active_id = $category->parent_id;
         }
         return redirect()->route('category.show', [$parent_id, 'active_tab' => $active_id])->with('success', 'Category successfully updated!');
     }
     return redirect()->route('category.show', $parent_id)->with('error', 'Problem updating Category!');
 }