/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $campaign = Campaign::first();
     $actions = Action::forCampaign($campaign)->get();
     $opened = $actions->filter(function ($action) {
         return $action->action === 'opened';
     })->groupBy('contact_id');
     $website = $actions->filter(function ($action) {
         return $action->action === 'website';
     })->groupBy('contact_id');
     $skipped = $actions->filter(function ($action) {
         return $action->action === 'skipped';
     })->groupBy('contact_id');
     $emailed = $actions->filter(function ($action) {
         return $action->action === 'email';
     })->groupBy('contact_id');
     $youtube = $actions->filter(function ($action) {
         return $action->action === 'youtube';
     })->groupBy('contact_id');
     $moreinfo = $actions->filter(function ($action) {
         return $action->action === 'moreinfo';
     })->groupBy('contact_id');
     $unsubscribed = Contact::where('unsubscribe', '=', 1);
     $openedPercentage = $campaign->emails->count() ? round($opened->count() / $campaign->emails->count() * 100, 2) : 0;
     $moreinfoPercentage = $campaign->emails->count() ? round($moreinfo->count() / $campaign->emails->count() * 100, 2) : 0;
     $websitePercentage = $campaign->emails->count() ? round($website->count() / $campaign->emails->count() * 100, 2) : 0;
     $skippedPercentage = $campaign->emails->count() ? round($skipped->count() / $campaign->emails->count() * 100, 2) : 0;
     $emailedPercentage = $campaign->emails->count() ? round($emailed->count() / $campaign->emails->count() * 100, 2) : 0;
     $youtubePercentage = $campaign->emails->count() ? round($youtube->count() / $campaign->emails->count() * 100, 2) : 0;
     $unsubscribedPercentage = $campaign->emails->count() ? round($unsubscribed->count() / $campaign->emails->count() * 100, 2) : 0;
     $sentPercentage = $campaign->emails->count() ? round($campaign->sentEmails->count() / $campaign->emails->count() * 100, 2) : 0;
     return view()->make('admin.index')->with(['campaign' => $campaign, 'actions' => $actions, 'openedPercentage' => $openedPercentage, 'websitePercentage' => $websitePercentage, 'skippedPercentage' => $skippedPercentage, 'emailedPercentage' => $emailedPercentage, 'youtubePercentage' => $youtubePercentage, 'moreinfoPercentage' => $moreinfoPercentage, 'unsubscribedPercentage' => $unsubscribedPercentage, 'sentPercentage' => $sentPercentage]);
 }