Пример #1
0
 public function unLikeGuide($id)
 {
     $guideLike = GuideLike::where('user_id', Auth::user()->id)->where('guide_id', $id)->first();
     if ($guideLike != null) {
         $guide = Guide::findOrFail($id);
         $guideLike->delete();
         $guide->updateLikes();
     }
     return redirect(URL::previous());
 }
Пример #2
0
 public static function exists($userId, $guideId)
 {
     return GuideLike::where('user_id', $userId)->where('guide_id', $guideId)->count() > 0;
 }
Пример #3
0
 public function updateLikes()
 {
     $this->likes = GuideLike::where('guide_id', $this->id)->count();
     $this->save();
 }