laravel-api-generator
laravel-api-generator copied to clipboard
sendResponse should has encoding parameters
I think it will be much more convenient if you add some lines to the AppBaseController->sendResponse method allowing seeing encoded json properly:
public function sendResponse($result, $message)
{
$headers = ['Content-type'=> 'application/json; charset=utf-8'];
return Response::json($this->makeResponse($result, $message), 200, $headers, JSON_UNESCAPED_UNICODE);
}
I’d like to be able to easily read the output instead of "...\u043a\u0440\u044b\u043b\u0430\u0442\u044b\u0445 \u0444\u0440\u0430\u0437..."
@zhekaus why you are getting output like,
"...\u043a\u0440\u044b\u043b\u0430\u0442\u044b\u0445 \u0444\u0440\u0430\u0437..." ?
Because it isn’t English but Cyrillic (Russian) in utf8 encoding. If I add headers parameter and JSON_UNESCAPED_UNICODE option, I’ll see Russian text.
Actually, we are already using Response::json
to send a response and it's not a general requirement. so can not add it as of now.
But it you want to do so, then you can do it by following steps:
- Create your own
AppBaseController
with the copy of package one - Publish Templates
- Modify
/resources/api-generator-templates/api/Controller.stub
&/resources/api-generator-templates/scaffold/Controller.stub
to use yourAppBaseController
instead of package one. (Don't forget to delete the templates which you are not using)