/** * Retrieve article by tag label. * * @param $tag * @return json */ public function tag($tag) { $article_tag = str_replace('-', ' ', $tag); $tag = new Tag(); $articles = $tag->tagArticle($article_tag); return ['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'articles' => $articles]; }
/** * Display a listing of the article by tags are given. * * @param Request $request * @param $tag * @return \Illuminate\Http\Response */ public function tag(Request $request, $tag) { /* * -------------------------------------------------------------------------- * Populating article by tag * -------------------------------------------------------------------------- * Reverse tag by slug form into plain name and select article by that * name, also construct breadcrumb stack, because we implement lazy * pagination via ajax so return json when 'page' variable exist. */ $article_tag = str_replace('-', ' ', $tag); $tag = new Tag(); $article = $tag->tagArticle($article_tag); $breadcrumb = ['Archive' => route('article.archive'), 'Tag' => '#', $article_tag => '#']; $next_ref = '#'; $prev_ref = '#'; if (Input::get('page', false) && $request->ajax()) { return $article; } else { return view('article.category', compact('breadcrumb', 'next_ref', 'prev_ref')); } }