Wedding Invitation
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

MainController.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\RSVP;
  5. use App\Models\GuestBook;
  6. use Illuminate\Support\Facades\Response;
  7. class MainController extends Controller
  8. {
  9. public function main(Request $request) {
  10. $rsvp = RSVP::all();
  11. $guestbooks = GuestBook::orderBy('created_at', 'desc')->take(5)->get();
  12. $totalPages = $guestbooks->count();
  13. $allguestbooks = GuestBook::orderBy('created_at', 'desc')->get();
  14. $host = $request->getHost();
  15. return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages', 'host', 'allguestbooks']));
  16. }
  17. public function saveRsvp(Request $request) {
  18. $host = $request->getHost();
  19. if ($host == 'rsvp.aliffayuna.com') {
  20. $vip = true;
  21. } else {
  22. $vip = false;
  23. }
  24. RSVP::create([
  25. 'name' => $request->name,
  26. 'member' => $request->member,
  27. 'phone' => $request->phone,
  28. 'is_vip' => $vip
  29. ]);
  30. session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
  31. return response()->json(['message' => 'Terima kasih kerana sudi menghadirkan diri!']);
  32. }
  33. public function saveSpeech(Request $request) {
  34. GuestBook::create([
  35. 'name' => $request->name,
  36. 'speech' => $request->speech
  37. ]);
  38. session()->flash('success', 'Terima kasih atas ucapan anda!');
  39. return response()->json(['message' => 'Terima kasih atas ucapan anda!']);
  40. }
  41. public function fetchGuestbook(Request $request)
  42. {
  43. $page = $request->input('page', 1);
  44. $guestbook = GuestBook::orderBy('created_at', 'desc')->take(5)->get()->forPage($page, 1);
  45. return response()->json([
  46. 'guestbook' => view('partials.guestbook', ['entry' => $guestbook->first()])->render(),
  47. ]);
  48. }
  49. public function attendance() {
  50. $vips = RSVP::where('is_vip', true)->get();
  51. $generals = RSVP::where('is_vip', false)->get();
  52. return view('attendance', compact(['vips', 'generals']));
  53. }
  54. public function downloadVipCsv()
  55. {
  56. $vips = RSVP::where('is_vip', true)->get();
  57. $csvData = "\xEF\xBB\xBF" . "Nama,Bilangan,No Tel\n";
  58. foreach ($vips as $vip) {
  59. $csvData .= "\t{$vip->name},{$vip->member},\t{$vip->phone}\n";
  60. }
  61. $fileName = "vip_data.csv";
  62. $headers = [
  63. 'Content-Type' => 'text/csv',
  64. 'Content-Disposition' => "attachment; filename=\"$fileName\"",
  65. ];
  66. return Response::make($csvData, 200, $headers);
  67. }
  68. public function downloadGeneralCsv()
  69. {
  70. $generals = RSVP::where('is_vip', false)->get();
  71. $csvData = "\xEF\xBB\xBF" . "Nama,Bilangan,No Tel\n";
  72. foreach ($generals as $general) {
  73. $csvData .= "\t{$general->name},{$general->member},\t{$general->phone}\n";
  74. }
  75. $fileName = "general_data.csv";
  76. $headers = [
  77. 'Content-Type' => 'text/csv',
  78. 'Content-Disposition' => "attachment; filename=\"$fileName\"",
  79. ];
  80. return Response::make($csvData, 200, $headers);
  81. }
  82. }