/** * Display all of the e-mail addresses. * * @return Response */ public function emails() { // Update e-mail dates Guest::where('email', '<>', '')->whereNull('email_date')->update(['email_date' => Carbon::now()]); // List non-blank e-mail dates $guests = Guest::whereNotNull('email_date')->orderBy('email_date', 'desc')->get(); // Generate a 2d list $mail_list = $guests->reduce(function ($acc, $item) { $acc[$item->email_date->format('l, F jS, Y')][] = $item->full_name . ' <' . $item->email . '>;'; return $acc; }, []); return view('classmates.emails', compact('mail_list')); }