/** * Travelers can like multiple journeys * * @return Illuminate\Database\Eloquent\Relations\HasMany */ public function likes_journey($with_id) { if (Like::where('traveler', '=', Auth::id())->where('likes_journey', '=', $with_id)->first()) { return TRUE; } else { return FALSE; } }
/** * Store a travelers' like * * @return Illuminate\Http\Response */ protected function like($uuid) { $like_details = ['traveler' => Auth::id(), 'likes_journey' => Journey::where('uuid', '=', $uuid)->first()->id]; if (Like::where($like_details)->count() == 0) { // The traveler hasn't already // liked this journey; Like it if (Like::create($like_details)) { $status = 200; } } else { // The traveler has already // liked this journey; So // we'll delete the like if (Like::where($like_details)->delete()) { $status = 204; } } $like_count = Like::where('traveler', '=', Auth::id())->count(); return json_encode(['status' => $status, 'likeCount' => $like_count]); }