Custom toReponse that is not JSON #436
-
I'm overwriting the toResponse function of my Data class. However, since we have to return XML instead of JSON I want to return a Response instead of a JsonReponse. This just works /**
* @param Request $request
*
* @return Response
*/
public function toResponse($request): Response
{
return new Response(
content: ArrayToXml::convert(
array: $this->toArray(),
),
headers: [
'Content-Type' => 'application/xml',
]
);
} However, we run into the phpstan error about the types:
Is there any what I can fix the error without a phpstan-ignore? If not, would it be an option to change the PHPdoc return type of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think you'll need to return a |
Beta Was this translation helpful? Give feedback.
-
See #437 |
Beta Was this translation helpful? Give feedback.
I think you'll need to return a
Symfony\Component\HttpFoundation\Response
to both captureIlluminate\Http\Respons
andIlluminate\Http\JsonResponse
. I'll merge the PR if you send it in!