/**
  * 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!');
 }