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

mrnaveed's avatar

How to get response in JSON form instead of string using curl ?

I've also tried curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

0 likes
2 replies
bit9labs's avatar

You could try the following Laravel 5.3+:

public function index(Request $request) {
...
if($request->expectsJson()) {
  return response()->json($data);
}
...
}

It looks like the function is wantsJson is Laravel 5.0-5.2

robrogers3's avatar

how are you accessing the page? if the browser directly then you need to use ajax.

add some details please.

Please or to participate in this conversation.