Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ha77an's avatar

Getting Excepting while using Api Laravel 8

API have 3 parameters

1: contact_no

2: message

3:client_id

When i try to send data in html and script format in message parameters like this


<a>Hi</a><script></script>

  

it through exception like this


Error: The GET method is not supported for this route. Supported methods: POST.

this issue only appears on the online server. In localhost its working fine

api.php code :


 Route::post('/receive-customer-messages', [App\Http\Controllers\Api\CustomerMessageController::class, 'receive_customer_message']);

0 likes
6 replies
martinbean's avatar

@ha77an Read your error message. You’re sending a GET request to an endpoint that’s expecting a POST.

jlrdw's avatar

How are you sending the data? You didn't show the code.

ha77an's avatar

when I try to send


message = "<a>Hi</a><script></script>"

exceptional will appear otherwise API working fine

ha77an's avatar

public function receive_customer_message(Request $request)
    {
        $rules= [
            'contact' => 'required',
            'client_id' => 'required',
            'message' => 'required',
        ];
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails()) {
            $response['status'] = 'empty';
            $response['message'] = $validator->errors()->first();
            return response()->json($response);
        }

// after validation i save the data into db
}

martinbean's avatar

@ha77an Again, you’re not showing the code on how you make the request. Until you do, no one can help.

ha77an's avatar

Actually, I'm building an email portal in this API I fetch the emails and message from the specific email account and save into database.

I found the solution. I will encode message data while sending to API and then decode it to save it into the database.

Please or to participate in this conversation.