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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Enquiry;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. class EnquiryController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. */
  11. public function index()
  12. {
  13. return "ENQUIRY API IS WORKING";
  14. }
  15. /**
  16. * Store a newly created resource in storage.
  17. */
  18. public function store(Request $request)
  19. {
  20. $messages = [
  21. 'name.required' => 'The name field is required.',
  22. 'email.required' => 'The email field is required.',
  23. 'email.email' => 'Please enter a valid email address.',
  24. 'phone.required' => 'The phone number field is required.',
  25. 'phone.regex' => 'The phone number format is invalid. It should contain 10 to 15 digits.',
  26. ];
  27. $validatedData = $request->validate([
  28. 'name' => 'required|string|max:255',
  29. 'email' => 'required|email|max:255',
  30. 'phone' => 'required|regex:/^[0-9]{10,15}$/',
  31. ], $messages);
  32. if($validatedData){
  33. Enquiry::create([
  34. 'name' => $request->name,
  35. 'email' => $request->email,
  36. 'phone' => $request->phone
  37. ]);
  38. return response()->json(['message' => 'ok'], 200);
  39. }
  40. return response()->json(['message' => 'error'], 400);
  41. }
  42. /**
  43. * Display the specified resource.
  44. */
  45. public function show(string $id)
  46. {
  47. //
  48. }
  49. /**
  50. * Update the specified resource in storage.
  51. */
  52. public function update(Request $request, string $id)
  53. {
  54. //
  55. }
  56. /**
  57. * Remove the specified resource from storage.
  58. */
  59. public function destroy(string $id)
  60. {
  61. //
  62. }
  63. }