示例#1
0
 public function postVote(Request $request, $id)
 {
     $vote = Vote::find($id);
     if (!$vote->is_active) {
         return redirect('/');
     } else {
         $voted = Voter::where('vote_id', '=', $id)->where('ip', '=', sprintf('%u', ip2long($request->ip())))->count();
         if ($voted) {
             return redirect('auth/logout');
         }
     }
     $inputs = $request->all();
     $voter = new Voter();
     $voter->ip = $request->ip();
     $voter->name = trim($inputs['name']);
     $voter->department = trim($inputs['department']);
     $voter->mobile = str_replace(' ', '', $inputs['mobile']);
     $voter->type_id = $inputs['type'];
     $voter->vote_id = $id;
     if ($voter->save()) {
         Voter::find($voter->id)->nominations()->sync($inputs['vote']);
         return redirect('vote/statistics/' . $id)->with('status', '投票保存成功');
     } else {
         return back()->withErrors('投票保存失败');
     }
 }