P
P
photosho2020-10-23 09:11:03
Laravel
photosho, 2020-10-23 09:11:03

How to force Laravel to return Content-Type JSON?

How to force laravel to set Content-Type header "application/json; charset=UTF-8"? I also do it through middleware:

public function handle($request, Closure $next) {
  $request->headers->set('Content-Type', 'application/json; charset=UTF-8');
  return $next($request);
}


(I hook to route via "->middleware('json')"), and via the controller:

return response()->json($result)->header('Content-Type', 'application/json; charset=UTF-8');


Anyway, in the browser the header is "content-type: text/html", and the response is not perceived as json.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question