Level 31
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In Laravel, I’m returning an API resource like this:
return (new UserResource($user))
->response()
->setStatusCode(Response::HTTP_CREATED);
This works fine, but I would also like to include a custom message in the JSON response (for example: "message" => "Successfully created").
What is the best way to add such custom fields/messages when returning API resources in Laravel?
Please or to participate in this conversation.