public function index($uri = NULL)
 {
     if (NULL === $uri) {
         return response()->redirectToRoute('page', 'chao-mung');
     }
     $infoUri = $this->_parseUri($uri);
     // Check term_slug is exists in database and any taxonomy is 'category'.
     $requestTerm = $this->_getTermBySlug($infoUri['term_slug'], 'category');
     if (!($isArticle = $infoUri['post_id'] > 0) and NULL === $requestTerm) {
         return response()->view("errors.404", ['exception' => NULL], 404);
     }
     // Check URI is reference to category or article...
     if ($isArticle) {
         // If URI reference to article...
         // Check post_id is belongs to specific 'category'.
         $hasTaxonomy = $this->_hasTaxonomy('category', $infoUri['post_id'], isset($requestTerm->term_taxonomy_id) ? $requestTerm->term_taxonomy_id : NULL);
         if (!($hasTaxonomy xor NULL === $requestTerm) or !$hasTaxonomy and $infoUri['term_slug'] !== '') {
             return response()->view("errors.404", ['exception' => NULL], 404);
         }
         $article = Post::find($infoUri['post_id']);
         if (NULL === $article) {
             return response()->view("errors.404", ['exception' => NULL], 404);
         }
         $termCategory =& $requestTerm;
         $parentCategories = $this->_getTermsBySlugSegments($infoUri['term_slugs']);
         $relCategories = $this->_getTermsByParent($termCategory->id);
         return view('article.show', compact('article', 'termCategory', 'parentCategories', 'relCategories'));
     } else {
         // If URI reference to category...
         // List of articles has same term_slug
         $articles = $this->_getPostsByTermTaxonomy($requestTerm->term_taxonomy_id);
         $termCategory =& $requestTerm;
         $parentCategories = $this->_getTermsBySlugSegments($infoUri['term_slugs']);
         $relCategories = $this->_getTermsByParent($termCategory->id);
         if ($relCategories->count() == 0 and $parentCategories->count() - 1 >= 0) {
             $relCategories = $this->_getTermsByParent($parentCategories[$parentCategories->count() - 1]->id);
         }
         return view('article.category', compact('articles', 'termCategory', 'parentCategories', 'relCategories'));
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param                 $id
  * @param PostFormRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($id, PostFormRequest $request)
 {
     $post = Post::find($id);
     $title = $request->input('post_title');
     $newCategory = $request->input('post_category');
     $post->update(['post_title' => trim($title), 'post_excerpt' => trim($request->input('post_excerpt')), 'post_content' => trim($request->input('post_content')), 'post_name' => str_slug($title), 'post_avatar' => trim($request->input('post_avatar'))]);
     $taxonomy = $post->taxonomy();
     $taxonomy->updateExistingPivot($taxonomy->first()->id, ['term_taxonomy_id' => $newCategory]);
     return redirect()->route('admin::@dmin-zone.posts.show', $id);
 }