<?php namespace App\Http\Controllers; use App\Models\Enquiry; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; class EnquiryController extends Controller { /** * Display a listing of the resource. */ public function index() { return "ENQUIRY API IS WORKING"; } /** * Store a newly created resource in storage. */ public function store(Request $request) { $messages = [ 'name.required' => '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) { // } }