コード例 #1
0
 public function handleSignPetition()
 {
     $userID = Input::get('user_id');
     $petitionID = Input::get('petition_id');
     $query = DB::table('signees')->where('petition_id', '=', $petitionID)->get();
     $signed = -1;
     foreach ($query as $q) {
         if ($q->user_id == $userID) {
             $signed = 0;
         }
     }
     if ($signed == -1) {
         $signee = new Signee();
         $signee->user_id = $userID;
         $signee->petition_id = $petitionID;
         $signee->save();
         return Redirect::to('petitions');
     } else {
         return Redirect::to('petitions')->with(array('alert' => 'You have already signed this petition', 'alert-class' => 'alert-danger'));
     }
     return var_dump($signed);
 }