예제 #1
0
 /**
  * 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);
     }
 }
예제 #2
0
 /**
  * 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'));
 }
예제 #3
0
 /**
  * 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')]);
 }
예제 #4
0
 /**
  * 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'));
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
파일: TrickOwner.php 프로젝트: qloog/site
 /**
  * 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);
 }
예제 #7
0
파일: Builder.php 프로젝트: wmk223/site
 /**
  * Gather the feed data to render.
  *
  * @return array
  */
 protected function getFeedData()
 {
     $data['tricks'] = $this->tricks->findForFeed();
     return $data;
 }
예제 #8
0
 /**
  * Get all the tricks to include in the sitemap.
  *
  * @return \Illuminate\Database\Eloquent\Collection|\App\Trick[]
  */
 public function getTricks()
 {
     return $this->tricks->findAllForSitemap();
 }
예제 #9
0
 /**
  * Show the homepage.
  *
  * @return \Response
  */
 public function getIndex()
 {
     $tricks = $this->tricks->findAllPaginated();
     return view('home.index', compact('tricks'));
 }
예제 #10
0
 /**
  * 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'));
 }