Wedding Invitation
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MainController.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 = "Nama,Bilangan,No Tel\n";
  58. foreach ($vips as $vip) {
  59. $csvData .= "{$vip->name},{$vip->member},{$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. }