/** * Display a listing of the category. * * @param $slug * @return \Illuminate\Http\Response */ public function category($slug) { $category_name = str_replace('-', ' ', $slug); $category = $this->category->where('category', 'like', $category_name)->firstOrFail(); $articles = $this->category->categoryArticle($category->id); $data = $this->reduceArticleData($articles); return ['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'articles' => $data]; }
/** * Display a listing of the category. * * @param Request $request * @param $slug * @return \Illuminate\Http\Response */ public function category(Request $request, $slug) { /* * -------------------------------------------------------------------------- * Populating article by category * -------------------------------------------------------------------------- * Reverse category 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. */ $categoryName = str_replace('-', ' ', $slug); $category = $this->category->where('category', 'like', $categoryName)->firstOrFail(); $articles = $this->category->categoryArticle($category->id); $breadcrumb = ['Archive' => route('article.archive'), $category->category => route('article.category', [$slug])]; $next_ref = '#'; $prev_ref = '#'; if (Input::get('page', false) && $request->ajax()) { return $articles; } else { return view('article.category', compact('breadcrumb', 'next_ref', 'prev_ref')); } }