/** * 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')); }
/** * Display a listing of the latest article. * * @param Request $request * @return \Illuminate\Http\Response */ public function latest(Request $request) { /* * -------------------------------------------------------------------------- * Public latest article * -------------------------------------------------------------------------- * Retrieve full latest page (with false param), this page implement lazy * pagination then return json if page variable exists, return view if it * does not. */ $latest = $this->article->latest(false); $breadcrumb = ['Archive' => route('article.archive'), 'Latest' => route('article.latest')]; $next_ref = route('article.headline'); $prev_ref = '#'; if (Input::get('page', false) && $request->ajax()) { return $latest; } else { return view('article.category', compact('breadcrumb', 'next_ref', 'prev_ref')); } }
/** * Fetch latest article. * * @return mixed */ public function latest() { $article = new Article(); $latest = $article->latest(false); $data = $this->reduceArticleData($latest); return response()->json(['request_id' => uniqid(), 'status' => 'success', 'articles' => $data, 'timestamp' => Carbon::now()]); }