示例#1
0
 public function exportGuest($id)
 {
     if (Gate::denies('download', Activity::class)) {
         abort(403);
     }
     $records = Activity::join('activity_subtitles', 'activities.subtitle_id', '=', 'activity_subtitles.id')->join('activity_titles', 'activity_subtitles.title_id', '=', 'activity_titles.id')->select(['activities.date_of_activity', 'activities.barangay', 'activity_titles.title', 'activity_subtitles.subtitle', 'activities.day_of_activity', 'activities.venue_of_activity', 'activities.conducted_by', 'activities.remarks'])->where('activities.id', '=', $id)->get();
     $recordsArray = [];
     foreach ($records as $record) {
         $recordsArray[] = ['date_of_activity', $record->date_of_activity];
         $recordsArray[] = ['barangay', $record->barangay];
         $recordsArray[] = ['title', $record->title];
         $recordsArray[] = ['subtitle', $record->subtitle];
         $recordsArray[] = ['day_of_activity', $record->day_of_activity];
         $recordsArray[] = ['venue_of_activity', $record->venue_of_activity];
         $recordsArray[] = ['conducted_by', $record->conducted_by];
         $recordsArray[] = ['remarks', $record->remarks];
         $recordsArray[] = [' ', ' '];
     }
     $records = Guest::join('activity_guest', 'activity_guest.guest_id', '=', 'guests.id')->select(['guests.last_name', 'guests.first_name', 'guests.age', 'guests.gender', 'guests.civil_status', 'guests.agency', 'guests.role', 'guests.email', 'guests.contact_number'])->where('activity_guest.activity_id', '=', $id)->orderBy('guests.last_name', 'asc')->orderBy('guests.first_name', 'asc')->get();
     $recordsArray[] = ['last_name', 'first_name', 'age', 'gender', 'civil_status', 'agency', 'role', 'email', 'contact_number'];
     foreach ($records as $record) {
         $recordsArray[] = $record->toArray();
     }
     $now = Carbon::now('Asia/Manila');
     $file_name = 'arp_activity_guest_attendance_' . $now->format('Ymd_His');
     Excel::create($file_name, function ($excel) use($recordsArray) {
         $excel->setTitle('ARP Activity Guest Attendance');
         $excel->setDescription('List of ARP Activity Guest Attendance');
         $excel->sheet('Activity Guest Attendance', function ($sheet) use($recordsArray) {
             $sheet->fromArray($recordsArray, null, 'A1', false, false);
         });
     })->download('xlsx');
 }