Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41400

How to check in Laravel if a POST request comes with form data or a JSON body? For a webhook API

I've created a webhook endpoint and now receiving requests with my Laravel application.

If request comes with the form data, I use $request->post();, if it has a json body I use $request->getContent().

I understand that there may not be both. Right?

My question is - how can I check if response comes with the form data or json body?

Upvotes: 0

Views: 2227

Answers (1)

KulaKrzysztof
KulaKrzysztof

Reputation: 11

I understand that you want check , whether request is Ajax or form data?

You can check this by using:

$request->ajax() 

Or by http headers.

Upvotes: 1

Related Questions