/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $turnout = Turnout::where('state_id', $request->input('state_id'))->first();
     if (!$turnout) {
         Turnout::create($request->except('_token'));
     } else {
         $turnout->update($request->except('_token', 'state_id'));
     }
     return redirect()->route('home');
 }
예제 #2
0
 public function turnoutByYear($year)
 {
     switch ($year) {
         case '2004':
             return \App\Turnout::where('state_id', $this->id)->pluck('turnout_2004');
             break;
         case '2008':
             return \App\Turnout::where('state_id', $this->id)->pluck('turnout_2008');
             break;
         case '2016':
             return ($this->turnoutByYear('2004') + $this->turnoutByYear('2008')) / 2;
             break;
         default:
             # code...
             break;
     }
 }