Browse Source

download vip

master
farhan 3 months ago
parent
commit
12ec031fad
3 changed files with 22 additions and 1 deletions
  1. 19
    0
      app/Http/Controllers/MainController.php
  2. 1
    0
      resources/views/attendance.blade.php
  3. 2
    1
      routes/web.php

+ 19
- 0
app/Http/Controllers/MainController.php View File

5
 use Illuminate\Http\Request;
5
 use Illuminate\Http\Request;
6
 use App\Models\RSVP;
6
 use App\Models\RSVP;
7
 use App\Models\GuestBook;
7
 use App\Models\GuestBook;
8
+use Illuminate\Support\Facades\Response;
8
 
9
 
9
 class MainController extends Controller
10
 class MainController extends Controller
10
 {
11
 {
66
 
67
 
67
         return view('attendance', compact(['vips', 'generals']));
68
         return view('attendance', compact(['vips', 'generals']));
68
     }
69
     }
70
+
71
+    public function downloadVipCsv()
72
+    {
73
+        $vips = RSVP::where('is_vip', true)->get();
74
+
75
+        $csvData = "Nama,Bilangan,No Tel\n";
76
+        foreach ($vips as $vip) {
77
+            $csvData .= "{$vip->name},{$vip->member},{$vip->phone}\n";
78
+        }
79
+
80
+        $fileName = "vip_data.csv";
81
+        $headers = [
82
+            'Content-Type' => 'text/csv',
83
+            'Content-Disposition' => "attachment; filename=\"$fileName\"",
84
+        ];
85
+
86
+        return Response::make($csvData, 200, $headers);
87
+    }
69
 }
88
 }

+ 1
- 0
resources/views/attendance.blade.php View File

30
                 @endforeach
30
                 @endforeach
31
                 </tbody>
31
                 </tbody>
32
             </table>
32
             </table>
33
+            <a href="{{ route('download.vip.csv') }}" class="btn btn-primary">Download VIP Data</a>
33
         </div>
34
         </div>
34
         
35
         
35
         <div>
36
         <div>

+ 2
- 1
routes/web.php View File

19
 Route::post('/saveSpeech', [MainController::class, 'saveSpeech'])->name('speech.save');
19
 Route::post('/saveSpeech', [MainController::class, 'saveSpeech'])->name('speech.save');
20
 Route::get('/guestbook', [MainController::class, 'fetchGuestbook'])->name('guestbook.ajax');
20
 Route::get('/guestbook', [MainController::class, 'fetchGuestbook'])->name('guestbook.ajax');
21
 
21
 
22
-Route::get('/admin/attendance', [MainController::class, 'attendance']);
22
+Route::get('/admin/attendance', [MainController::class, 'attendance']);
23
+Route::get('/download-vip-csv', [MainController::class, 'downloadVipCsv'])->name('download.vip.csv');

Loading…
Cancel
Save