瀏覽代碼

download vip

master
farhan 3 月之前
父節點
當前提交
12ec031fad
共有 3 個檔案被更改,包括 22 行新增1 行删除
  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 查看文件

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
5 5
 use Illuminate\Http\Request;
6 6
 use App\Models\RSVP;
7 7
 use App\Models\GuestBook;
8
+use Illuminate\Support\Facades\Response;
8 9
 
9 10
 class MainController extends Controller
10 11
 {
@@ -66,4 +67,22 @@ class MainController extends Controller
66 67
 
67 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 查看文件

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

+ 2
- 1
routes/web.php 查看文件

@@ -19,4 +19,5 @@ Route::post('/saveRsvp', [MainController::class, 'saveRsvp'])->name('rsvp.save')
19 19
 Route::post('/saveSpeech', [MainController::class, 'saveSpeech'])->name('speech.save');
20 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…
取消
儲存