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()); }
public static function exists($userId, $guideId) { return GuideLike::where('user_id', $userId)->where('guide_id', $guideId)->count() > 0; }
public function updateLikes() { $this->likes = GuideLike::where('guide_id', $this->id)->count(); $this->save(); }