Wedding Invitation
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

MainController.php 3.3KB

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