2

I want to remove header information from laravel 5.1 response. I have used middleware for filter output.

$response = $next($request);
dd($response);

It gives me out put with header information. Check attached screen shot. enter image description here

How to read either #data or how to remove Header information from $response?

Because when I try to json_decode it shows 'null'

I want JSON to be send only so I have use it with my application.

1
  • Provide some more details, Question is not much clear Commented Dec 26, 2016 at 6:25

3 Answers 3

1

Finally got the solution

$response->getData() or $response->getContent()

getData()/getContent() function returns only data without any extra parameter (headers)

Sign up to request clarification or add additional context in comments.

Comments

1

It works for me

return response()->json($response)->getData()

It will remove header, exception data from the object.

Comments

0

If you want your method to return a json object your can use

return response()->json($response, $status);

Note that you can add an optional parameter $status

for HTTP status codes which can be very useful if you're using Javascript to manipulate the returned data and throw any necessary exceptions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.