Wedding Invitation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainController.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\RSVP;
  5. use App\Models\GuestBook;
  6. class MainController extends Controller
  7. {
  8. public function main(Request $request) {
  9. $rsvp = RSVP::all();
  10. $guestbooks = GuestBook::orderBy('created_at', 'desc')->take(5)->get();
  11. $totalPages = $guestbooks->count();
  12. $host = $request->getHost();
  13. // if ($host == 'aliffayuna.com') {
  14. // return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages', 'host']));
  15. // } else if ($host == 'rsvp.aliffayuna.com') {
  16. // return view('rsvp-digital-card');
  17. // } else {
  18. // return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages', 'host']));
  19. // // return view('rsvp-digital-card');
  20. // }
  21. return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages', 'host']));
  22. }
  23. public function saveRsvp(Request $request) {
  24. RSVP::create([
  25. 'name' => $request->name,
  26. 'member' => $request->member,
  27. 'phone' => $request->phone
  28. ]);
  29. session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
  30. return response()->json(['message' => 'Terima kasih kerana sudi menghadirkan diri!']);
  31. }
  32. public function saveSpeech(Request $request) {
  33. GuestBook::create([
  34. 'name' => $request->name,
  35. 'speech' => $request->speech
  36. ]);
  37. session()->flash('success', 'Terima kasih atas ucapan anda!');
  38. return response()->json(['message' => 'Terima kasih atas ucapan anda!']);
  39. }
  40. public function fetchGuestbook(Request $request)
  41. {
  42. $page = $request->input('page', 1); // Default to page 1 if no page is provided
  43. $guestbook = GuestBook::orderBy('created_at', 'desc')->take(5)->get()->forPage($page, 1);
  44. return response()->json([
  45. 'guestbook' => view('partials.guestbook', ['entry' => $guestbook->first()])->render(),
  46. ]);
  47. }
  48. }