I want to encode the JSON responses of my API to UTF-8, but every time I make a response I don't want to do this:
return response()->json($res,200,['Content-type'=>'application/json;charset=utf-8'],JSON_UNESCAPED_UNICODE);
So I thought about making a middleware for all API routes which handle(...)
function would be this:
public function handle($request, Closure $next) {
$response = $next($request);
$response->header('Content-type','application/json; charset=utf-8');
return $next($request);
}
The problem is that it doesn't work, the Content-type
header of my responses is still application/json
and not application/json; charset=utf-8
; maybe because the json(...)
function already sets a Content-type
header and I cannot override it.
How should I do?
Thank you for your help.