/**
  * Handle the view trick event.
  *
  * @param \Tricks\Trick $trick
  *
  * @return void
  */
 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);
     }
     $this->view('search.result', compact('tricks', 'term'));
 }
Beispiel #3
0
 /**
  * Handle the creation of a tag.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postIndex()
 {
     $trickid = $this->tricks->findById(\Input::get('trickid'));
     $trickid->trick_status = \Input::get('tt');
     $trickid->save();
     $tricks = $this->tricks->findAllPaginatedAdmin();
     $users = $this->users->findAllPaginated();
     $this->view('admin.tricks.list', compact('tricks', 'users'));
 }
 /**
  * Increment the view count on the given trick.
  *
  * @param  \Trick $trick
  * @return \Trick
  */
 private function incrementViews($trick)
 {
     $viewed = Session::get('viewed_tricks', []);
     if (!array_key_exists($trick->id, $viewed)) {
         $trick = $this->tricks->incrementViews($trick);
     }
     $viewed[$trick->id] = time();
     Session::put('viewed_tricks', $viewed);
     return $trick;
 }
 /**
  * Show the browse most commented tricks page.
  *
  * @return \Response
  */
 public function getBrowseComments()
 {
     $tricks = $this->tricks->findMostCommented();
     $type = 'Most commented';
     $pageTitle = 'Browsing Most Commented Laravel Tricks';
     $this->view('browse.index', compact('tricks', 'type', 'pageTitle'));
 }
Beispiel #6
0
 /**
  * Show the browse most commented tricks page.
  *
  * @return \Response
  */
 public function getBrowseComments()
 {
     $tricks = $this->tricks->findMostCommented();
     $type = \Lang::get('browse.most_commented');
     $pageTitle = \Lang::get('browse.browsing_most_commented_tricks');
     $this->view('browse.index', compact('tricks', 'type', 'pageTitle'));
 }
 /**
  * Add URLs to dynamic pages of the site.
  *
  * @return void
  */
 public function addDynamicRoutes()
 {
     $tricks = $this->tricks->findAllForSitemap();
     foreach ($tricks as $trick) {
         $this->sitemap->add(URL::to("tricks/{$trick->slug}"), $trick->created_at, '0.9', 'weekly');
     }
     $categories = $this->categories->findAll();
     foreach ($categories as $category) {
         $this->sitemap->add(URL::to("categories/{$category->slug}"), $category->created_at, '0.9', 'daily');
     }
     $tags = $this->tags->findAll();
     foreach ($tags as $tag) {
         $this->sitemap->add(URL::to("tags/{$tag->slug}"), $tag->created_at, '0.9', 'daily');
     }
     return $this->sitemap;
 }
 /**
  * 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' => \Lang::get('user_tricks.trick_deleted')]);
 }
 /**
  * Delete a trick from the database.
  *
  * @param  string $slug
  * @return \Illuminate\Http\RedirectResponse
  */
 public function getDelete($slug)
 {
     $trick = $this->trick->findBySlug($slug);
     if ($trick->user_id != Auth::user()->id) {
         return \Lang::get('user_tricks.trick_does_not_belong_to_you');
     }
     $trick->tags()->detach();
     $trick->categories()->detach();
     $trick->delete();
     return $this->redirectRoute('user.index', null, ['success' => \Lang::get('user_tricks.trick_deleted')]);
 }
 /**
  * Delete a trick from the database.
  *
  * @param  string $slug
  * @return \Illuminate\Http\RedirectResponse
  */
 public function getDelete($slug)
 {
     $trick = $this->trick->findBySlug($slug);
     if ($trick->user_id != Auth::user()->id) {
         return "This trick doesn't belong to you";
     }
     $trick->tags()->detach();
     $trick->categories()->detach();
     $trick->delete();
     return $this->redirectRoute('user.index', null, ['success' => 'Trick has been deleted']);
 }
 /**
  * Handle the liking of a trick.
  *
  * @param string $slug
  *
  * @return \Response
  */
 public function postLike($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);
 }
 /**
  * Show the homepage.
  *
  * @return \Response
  */
 public function getIndex()
 {
     $tricks = $this->tricks->findAllPaginated();
     $this->view('home.index', compact('tricks'));
 }
 /**
  * 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);
 }
 /**
  * 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);
     $this->view('user.public', compact('user', 'tricks'));
 }
 /**
  * Gather the feed data to render.
  *
  * @return array
  */
 protected function getFeedData()
 {
     $data['tricks'] = $this->tricks->findForFeed();
     return $data;
 }
 /**
  * Build the specified type of feed (ATOM or RSS).
  *
  * @param  string $type
  * @return \Response
  */
 private function buildFeed($type)
 {
     $data['tricks'] = $this->tricks->findForFeed();
     $contentType = $this->getContentType($type);
     return Response::view("feeds.{$type}", $data, 200, ['Content-Type' => $contentType . '; charset=UTF-8']);
 }
 /**
  * Get all the tricks to include in the sitemap.
  *
  * @return \Illuminate\Database\Eloquent\Collection|\Tricks\Trick[]
  */
 public function getTricks()
 {
     return $this->tricks->findAllForSitemap();
 }