Example #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);
 }
@if($petitions->isEmpty())
<p>No Active Petitions</p>
@else
<table class="table table-condensed">
	<thead>
		<tr>
			<th>Class Name</th>
			<th>Signees</th>
			<th>Subject</th>
		</tr>
	</thead>
	<tbody>
		@foreach($petitions as $petition)
		<?php 
$signee = Signee::where('petition_id', '=', $petition->id);
?>
		<tr>
			<td>{{ $petition->class_name }}</td>
			<td>{{ $signee->count() }}</td>
			<td>{{ $petition->subject }}</td>
			<td>
				<a href="{{ action('PetitionController@showPetition', $petition->id) }}" 
					class="btn btn-default">View</a>
			@if(Auth::user() -> role == 'Admin')
				<a href="{{ action('PetitionController@handleDeletePetition', $petition->id) }}" class="btn btn-danger">Delete</a>
			@endif
			</td>
		</tr>
		@endforeach
	</tbody>