public function voteUp(Request $request) { $poll = Option::with('poll')->find($request->option)->poll; $profile = Profile::find(Auth::user()->profile->id); if ($poll->profile->contains($profile->id)) { return redirect()->back()->withMessage('Your have already voted for this poll')->withStatus('error'); } else { $profile->poll()->attach($poll->id, ['option_id' => $request->option]); return redirect()->back()->withMessage('Your Vote has been registered')->withStatus('success'); } }