public function editServer($id) { $server = serverModel::where('id', $id)->first(); return view('admin/editServer', ['server' => $server]); }
public function addVote(Request $request) { $this->validate($request, ['g-recaptcha-response' => 'required|recaptcha']); $id = $request->input('server_id'); $settings = Setting::find(1); $interval = $settings->voteInterval; $ip = getHostByName(php_uname('n')); //Check if user alredy voted in 24h $vote = Vote::where('ip', $ip)->first(); if ($vote != null) { if ($vote->updated_at->addHours($interval) > Carbon::now()) { //already voted return redirect('server/' . $id)->withErrors('You have already voted. Now you can vote after ' . $interval . ' hours from your voting time'); } } //Deletes old record Vote::where('ip', $ip)->delete(); $server = serverModel::where('id', $id)->first(); $votes = $server->votes; $server->votes = $votes + 1; $server->save(); $vote = new Vote(); $vote->ip = $ip; $vote->save(); return redirect('server/' . $id)->with('status', 'You have successfully voted!'); }