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

MainController.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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" . "Nama,Bilangan,No Tel\n";
  62. foreach ($vips as $vip) {
  63. $csvData .= "\t{$vip->name},{$vip->member},\t{$vip->phone}\n";
  64. }
  65. $fileName = "vip_data.csv";
  66. $headers = [
  67. 'Content-Type' => 'text/csv',
  68. 'Content-Disposition' => "attachment; filename=\"$fileName\"",
  69. ];
  70. return Response::make($csvData, 200, $headers);
  71. }
  72. public function downloadGeneralCsv()
  73. {
  74. $generals = RSVP::where('is_vip', false)->get();
  75. $csvData = "\xEF\xBB\xBF" . "Nama,Bilangan,No Tel\n";
  76. foreach ($generals as $general) {
  77. $csvData .= "\t{$general->name},{$general->member},\t{$general->phone}\n";
  78. }
  79. $fileName = "general_data.csv";
  80. $headers = [
  81. 'Content-Type' => 'text/csv',
  82. 'Content-Disposition' => "attachment; filename=\"$fileName\"",
  83. ];
  84. return Response::make($csvData, 200, $headers);
  85. }
  86. }