Beispiel #1
0
 /**
  * Show all votes in JSON form.
  * TODO: There should be a better way to do this.
  *
  * @return \Illuminate\Http\Response
  */
 public function getVotes($terms = [])
 {
     Term::past()->get()->each(function ($term) use(&$terms) {
         $terms[] = ['id' => $term, 'start' => $term->starts_at->toDateString(), 'end' => $term->ends_at->toDateString(), 'candidates' => $term->candidates()->join('users', 'users.id', '=', 'candidates.user_id')->select(['candidates.id AS candidate_id', 'users.id AS user_id', 'users.facebook_id', 'users.name'])->get(), 'votes' => $term->votes()->join('users', 'users.id', '=', 'votes.user_id')->select(['votes.candidate_id', 'users.uuid'])->get()];
     });
     return response()->json(['terms' => $terms]);
 }