/** * Handle the view trick event. * * @param \App\Trick $trick */ public function handle($trick) { if (!$this->hasViewedTrick($trick)) { $trick = $this->tricks->incrementViews($trick); $this->storeViewedTrick($trick); } }
/** * Show the search results page. * * @return \Response */ public function getIndex() { $term = e(Input::get('q')); $tricks = null; if (!empty($term)) { $tricks = $this->tricks->searchByTermPaginated($term, 12); } return view('search.result', compact('tricks', 'term')); }
/** * Delete a trick from the database. * * @param string $slug * * @return \Illuminate\Http\RedirectResponse */ public function getDelete($slug) { $trick = $this->trick->findBySlug($slug); $trick->tags()->detach(); $trick->categories()->detach(); $trick->delete(); return $this->redirectRoute('user.index', null, ['success' => trans('user_tricks.trick_deleted')]); }
/** * Show the browse most commented tricks page. * * @return \Response */ public function getBrowseComments() { $tricks = Cache::get('most_commented', function () { $tricks = $this->tricks->findMostCommented(); Cache::put('most_commented', $tricks, 60); return $tricks; }); $type = trans('browse.most_commented'); $pageTitle = trans('browse.browsing_most_commented_tricks'); return view('browse.index', compact('tricks', 'type', 'pageTitle')); }
/** * Handle the liking of a trick. * * @param string $slug * * @return \Response */ public function postLike(Request $request, $slug) { if (!$request->ajax() || !Auth::check()) { $this->redirectRoute('browse.recent'); } $trick = $this->tricks->findBySlug($slug); if (is_null($trick)) { return Response::make('error', 404); } $user = Auth::user(); $voted = $trick->votes()->whereUserId($user->id)->first(); if (!$voted) { $user = $trick->votes()->attach($user->id, ['created_at' => new \DateTime(), 'updated_at' => new \DateTime()]); $trick->vote_cache = $trick->vote_cache + 1; } else { $trick->votes()->detach($voted->id); $trick->vote_cache = $trick->vote_cache - 1; } $trick->save(); return Response::make($trick->vote_cache, 200); }
/** * Determine whether the user owns the trick. * * @param string $slug * @param int $userId * * @return bool */ protected function isTrickOwnedByUser($slug, $userId) { return $this->tricks->isTrickOwnedByUser($slug, $userId); }
/** * Gather the feed data to render. * * @return array */ protected function getFeedData() { $data['tricks'] = $this->tricks->findForFeed(); return $data; }
/** * Get all the tricks to include in the sitemap. * * @return \Illuminate\Database\Eloquent\Collection|\App\Trick[] */ public function getTricks() { return $this->tricks->findAllForSitemap(); }
/** * Show the homepage. * * @return \Response */ public function getIndex() { $tricks = $this->tricks->findAllPaginated(); return view('home.index', compact('tricks')); }
/** * Show the user's public profile page. * * @param string $username * * @return \Response */ public function getPublic($username) { $user = $this->users->requireByUsername($username); $tricks = $this->tricks->findAllForUser($user); return view('user.public', compact('user', 'tricks')); }