How do I get HTTP Request body content in Laravel | How to return JSON Request body in Response in Laravel | How to add new parameter in HTTP request body in Laravel

So many time we need to return in REST APIs the request body. For example if you send a POST request with some parameters and you wanted you API access token along with the request body parameters which you sent.

Like below example:

Here is the Request body:

And now you wanted to get register and access token in response along with above request body like below:

How can we do this in Laravel????

Here is the answer of this question. You can get the HTTP request body in Laravel by following code:

Now if you wanted to send the request body with along with access token in JSON response in Laravel, You can do it like following example:

So finally function to return the JSON response after registration of the user looks like:

 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *