/** * Display the specified article. * * @param int $slug * @return \Illuminate\Http\Response */ public function show($slug) { /* * -------------------------------------------------------------------------- * Populate single article view * -------------------------------------------------------------------------- * Find published article by slug, build breadcrumb stack, retrieve article * author, article tags, related and popular article. */ $article = $this->article->whereSlug($slug)->firstOrFail(); if ($article->status == 'pending') { return view('article.pending', compact('article')); } if ($article->status == 'published') { $category = $article->subcategory->category->category; $subcategory = $article->subcategory->subcategory; $comments = $article->comments; $breadcrumb = ['Archive' => route('article.archive'), $category => route('article.category', [str_slug($category)]), $subcategory => route('article.subcategory', [str_slug($category), str_slug($subcategory)])]; $previous_article = $this->article->navigateArticle($article->id, 'prev'); $next_article = $this->article->navigateArticle($article->id, 'next'); $prev_ref = $previous_article != null ? route('article.show', [$previous_article->slug]) : '#'; $next_ref = $next_article != null ? route('article.show', [$next_article->slug]) : '#'; $tags = $article->tags()->get(); $related = $this->article->related($article->id); $popular = $this->article->mostPopular(5); $contributor = new Contributor(); $author = $contributor->profile($article->contributor->username); return view('article.article', compact('breadcrumb', 'prev_ref', 'next_ref', 'article', 'author', 'comments', 'tags', 'related', 'popular')); } else { abort(404); } }
/** * Display a listing of the index resource. * * @return \Illuminate\Http\Response */ public function index() { /* * -------------------------------------------------------------------------- * Retrieve featured posts from Article model * -------------------------------------------------------------------------- * Headline : indicate article with headline state * Trending : indicate article with trending state * Popular : the top of post sort by most viewed on last 3 months * Ranked : the top of post sort by most stared * Latest : last published article */ $article = new Article(); $featured = $article->headline(); $trending = $article->trending(); $popular = $article->mostPopular(); $ranked = $article->mostRanked(); $latest = $article->latest(); /* * -------------------------------------------------------------------------- * Retrieve featured category * -------------------------------------------------------------------------- * Selecting the most viewed articles on top 4 categories */ $category = new Category(); $summary = $category->featured(); return view('pages.index', compact('featured', 'popular', 'ranked', 'trending', 'latest', 'summary')); }