public function run()
 {
     DB::table('kiwanis_attendees')->delete();
     $faker = Faker::create();
     $cerf_ids = Cerf::all()->lists('id')->toArray();
     for ($counter = 0; $counter < 30; $counter++) {
         $rand_cerf_id = $cerf_ids[array_rand($cerf_ids)];
         KiwanisAttendee::create(array('cerf_id' => $rand_cerf_id, 'name' => $faker->city . ' Kiwanis Club', 'members_attended' => $faker->randomDigit));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $input = $request->all();
     /*
      * Creates Kiwanis Family Club attendees.
      */
     if (array_key_exists('kiwanis_club_name', $input)) {
         foreach ($input['kiwanis_club_name'] as $index => $kiwanis_club) {
             $kiwanisAttendeeAttributes = ['cerf_id' => session()->get('cerf_id'), 'name' => $kiwanis_club, 'members_attended' => $input['num_members'][$index]];
             KiwanisAttendee::create($kiwanisAttendeeAttributes);
         }
     }
     return redirect()->action('CerfsController@overview');
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function show($id)
 {
     $cerf = Cerf::find($id);
     if (!(Auth::user()->hasRole('Officer') || Auth::user()->hasRole('Administrator') || Auth::id() === $cerf->user_id)) {
         redirect()->action('CerfsController@overview');
     }
     $activities = Activity::where('cerf_id', $cerf->id)->get();
     $kiwanisAttendees = KiwanisAttendee::where('cerf_id', $cerf->id)->get();
     $serviceHoursSum = $activities->sum('service_hours') + $activities->sum('planning_hours') + $activities->sum('traveling_hours');
     $adminHoursSum = $activities->sum('admin_hours');
     $socialHoursSum = $activities->sum('social_hours');
     $event = $cerf->event;
     $tagCategories = [];
     for ($index = 1; $index <= 4; $index++) {
         $currentTags = [];
         $tags = $event->tags()->where('cerf_id', $cerf->id)->where('category_id', $index)->get();
         foreach ($tags as $tag) {
             array_push($currentTags, $tag->name . ' (' . $tag->abbreviation . ')');
         }
         $tagCategories[EventCategory::find($index)->name] = $currentTags;
     }
     $drivers = [];
     foreach ($activities as $activity) {
         if ($activity->mileage > 0) {
             $drivers[$activity->name] = $activity->mileage;
         }
     }
     return view('pages.cerfs.show', compact('cerf', 'activities', 'kiwanisAttendees', 'serviceHoursSum', 'adminHoursSum', 'socialHoursSum', 'tagCategories', 'drivers'));
 }