123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
-
- namespace App\Http\Controllers;
-
- use Illuminate\Http\Request;
- use App\Models\RSVP;
- use App\Models\GuestBook;
- use Illuminate\Support\Facades\Response;
-
- class MainController extends Controller
- {
- public function main(Request $request) {
- $rsvp = RSVP::all();
- $guestbooks = GuestBook::orderBy('created_at', 'desc')->take(5)->get();
- $totalPages = $guestbooks->count();
- $allguestbooks = GuestBook::orderBy('created_at', 'desc')->get();
-
- $host = $request->getHost();
-
- return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages', 'host', 'allguestbooks']));
- }
-
- public function saveRsvp(Request $request) {
- $host = $request->getHost();
-
- if ($host == 'rsvp.aliffayuna.com') {
- $vip = true;
- } else {
- $vip = false;
- }
- RSVP::create([
- 'name' => $request->name,
- 'member' => $request->member,
- 'phone' => $request->phone,
- 'is_vip' => $vip
- ]);
-
- session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
-
- return response()->json(['message' => 'Terima kasih kerana sudi menghadirkan diri!']);
- }
-
- public function saveSpeech(Request $request) {
- GuestBook::create([
- 'name' => $request->name,
- 'speech' => $request->speech
- ]);
-
- session()->flash('success', 'Terima kasih atas ucapan anda!');
-
- return response()->json(['message' => 'Terima kasih atas ucapan anda!']);
- }
-
- public function fetchGuestbook(Request $request)
- {
- $page = $request->input('page', 1);
- $guestbook = GuestBook::orderBy('created_at', 'desc')->take(5)->get()->forPage($page, 1);
-
- return response()->json([
- 'guestbook' => view('partials.guestbook', ['entry' => $guestbook->first()])->render(),
- ]);
- }
-
- public function attendance() {
- $vips = RSVP::where('is_vip', true)->get();
- $generals = RSVP::where('is_vip', false)->get();
-
- return view('attendance', compact(['vips', 'generals']));
- }
-
- public function downloadVipCsv()
- {
- $vips = RSVP::where('is_vip', true)->get();
-
- $csvData = "\xEF\xBB\xBF" . "Nama,Bilangan,No Tel\n";
- foreach ($vips as $vip) {
- $csvData .= "\t{$vip->name},{$vip->member},\t{$vip->phone}\n";
- }
-
- $fileName = "vip_data.csv";
- $headers = [
- 'Content-Type' => 'text/csv',
- 'Content-Disposition' => "attachment; filename=\"$fileName\"",
- ];
-
- return Response::make($csvData, 200, $headers);
- }
-
- public function downloadGeneralCsv()
- {
- $generals = RSVP::where('is_vip', false)->get();
-
- $csvData = "\xEF\xBB\xBF" . "Nama,Bilangan,No Tel\n";
- foreach ($generals as $general) {
- $csvData .= "\t{$general->name},{$general->member},\t{$general->phone}\n";
- }
-
- $fileName = "general_data.csv";
- $headers = [
- 'Content-Type' => 'text/csv',
- 'Content-Disposition' => "attachment; filename=\"$fileName\"",
- ];
-
- return Response::make($csvData, 200, $headers);
- }
- }
|