'The name field is required.', 'email.required' => 'The email field is required.', 'email.email' => 'Please enter a valid email address.', 'phone.required' => 'The phone number field is required.', 'phone.regex' => 'The phone number format is invalid. It should contain 10 to 15 digits.', ]; $validatedData = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'required|email|max:255', 'phone' => 'required|regex:/^[0-9]{10,15}$/', ], $messages); if($validatedData){ Enquiry::create([ 'name' => $request->name, 'email' => $request->email, 'phone' => $request->phone ]); return response()->json(['message' => 'ok'], 200); } return response()->json(['message' => 'error'], 400); } /** * Display the specified resource. */ public function show(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }