Wedding Invitation
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MainController.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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']));
  15. } else if ($host == 'rsvp.aliffayuna.com') {
  16. return view('rsvp-digital-card');
  17. } else {
  18. return view('digital-card', compact(['rsvp', 'guestbooks', 'totalPages']));
  19. // return view('rsvp-digital-card');
  20. }
  21. }
  22. public function saveRsvp(Request $request) {
  23. RSVP::create([
  24. 'name' => $request->name,
  25. 'member' => $request->member,
  26. 'phone' => $request->phone
  27. ]);
  28. session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
  29. return response()->json(['message' => 'Terima kasih kerana sudi menghadirkan diri!']);
  30. }
  31. public function saveSpeech(Request $request) {
  32. GuestBook::create([
  33. 'name' => $request->name,
  34. 'speech' => $request->speech
  35. ]);
  36. session()->flash('success', 'Terima kasih atas ucapan anda!');
  37. return response()->json(['message' => 'Terima kasih atas ucapan anda!']);
  38. }
  39. public function fetchGuestbook(Request $request)
  40. {
  41. $page = $request->input('page', 1); // Default to page 1 if no page is provided
  42. $guestbook = GuestBook::orderBy('created_at', 'desc')->take(5)->get()->forPage($page, 1);
  43. return response()->json([
  44. 'guestbook' => view('partials.guestbook', ['entry' => $guestbook->first()])->render(),
  45. ]);
  46. }
  47. }