Reputation: 2785
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.
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.
Upvotes: 2
Views: 4093
Reputation: 624
It works for me
return response()->json($response)->getData()
It will remove header, exception data from the object.
Upvotes: 1
Reputation: 717
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.
Upvotes: 0
Reputation: 2785
Finally got the solution
$response->getData()
or $response->getContent()
getData()/getContent()
function returns only data without any extra parameter (headers)
Upvotes: 1