public function getBattle($id) { $battle = Battle::findOrFail($id); $user = Auth::user(); if (is_null($user)) { return response('Unauthorized', 401); } $profilePreview1 = array('user_id' => $battle->rapper1_id, 'username' => User::findOrFail($battle->rapper1_id)->username, 'profile_picture' => User::findOrFail($battle->rapper1_id)->getProfilePicture()); $profilePreview2 = array('user_id' => $battle->rapper2_id, 'username' => User::findOrFail($battle->rapper2_id)->username, 'profile_picture' => User::findOrFail($battle->rapper2_id)->getProfilePicture()); $userVote = $user->votes()->where('battle_id', $battle->id)->get()->first(); $votedFor = $userVote == null ? null : $userVote->rapper_number; $voting = array('votes_rapper1' => $battle->votes_rapper1, 'votes_rapper2' => $battle->votes_rapper2, 'voted_for' => $votedFor, 'open' => $battle->isOpenVoting()); $battleInfo = array('id' => $battle->id, 'video_url' => $battle->getVideoURL(), 'rapper1' => $profilePreview1, 'rapper2' => $profilePreview2, 'voting' => $voting); return response()->json($battleInfo); }