Пример #1
0
 public function show($id)
 {
     $guide = Guide::findOrFail($id);
     $topNotes = Note::topNotes()->with('user')->take(6)->get();
     $guide->load('comments.user');
     $guide->incHits();
     $faved = Auth::check() && GuideFav::exists(Auth::user()->id, $guide->id);
     $liked = Auth::check() && GuideLike::exists(Auth::user()->id, $guide->id);
     return view('guide.show', compact('guide', 'faved', 'liked', 'topNotes'));
 }
Пример #2
0
 public function unFavGuide($id)
 {
     $guideFav = GuideFav::where('user_id', Auth::user()->id)->where('guide_id', $id)->first();
     if ($guideFav != null) {
         $guide = Guide::findOrFail($id);
         $guideFav->delete();
         $guide->updateFavs();
     }
     return redirect(URL::previous());
 }
Пример #3
0
 public static function exists($userId, $guideId)
 {
     return GuideFav::where('user_id', $userId)->where('guide_id', $guideId)->count() > 0;
 }
Пример #4
0
 public function updateFavs()
 {
     $this->favs = GuideFav::where('guide_id', $this->id)->count();
     $this->save();
 }