/** * 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 the specified article. * * @param Request $requests * @param $slug * @return \Illuminate\Http\Response */ public function show(Request $requests, $slug) { // retrieve article and related data $article = $this->article->whereSlug($slug)->with('subcategory', 'subcategory.category', 'tags')->firstOrFail(); // retrieve contributor and profile $contributor = new Contributor(); $contributor_id = $requests->get('contributor_id'); $username = $article->contributor->username; $author = $contributor->profile($username, false, $contributor_id, true); unset($author->token); unset($author->api_token); unset($author->email); unset($author->gender); unset($author->birthday); unset($author->contact); unset($author->facebook); unset($author->twitter); unset($author->googleplus); unset($author->instagram); unset($author->vendor); unset($author->mobile_notification); unset($author->email_subscription); unset($author->email_message); unset($author->email_follow); unset($author->email_feed); unset($author->created_at); unset($author->updated_at); unset($author->following_status); unset($author->following_text); unset($author->avatar); unset($author->cover); unset($author->contributor_ref); // retrieve rating $rating = round($article->ratings()->avg('rate')); // reduce related article data $related = $this->article->related($article->id); $related->map(function ($row) { unset($row->id); unset($row->content); unset($row->view); unset($row->featured); }); // reduce tags data $tags = $article->tags; $tags->map(function ($tag) { unset($tag->created_at); unset($tag->updated_at); }); $article = $article->toArray(); $article['content'] = str_replace('src="//www.youtube.com/', 'src="https://www.youtube.com/', $article['content']); $article['tags'] = $tags; $article['contributor'] = $author; $article['rating'] = $rating; $article['related'] = $related; return response()->json(['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'article' => $article]); }