Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include message in success response #180

Open
LubySagia opened this issue Jan 31, 2022 · 1 comment
Open

Include message in success response #180

LubySagia opened this issue Jan 31, 2022 · 1 comment

Comments

@LubySagia
Copy link

{ "status": 200, "success": true, "message": "Logged out successfully!", "data": null }

Is there any way to include a message to success respond like the above?

@jupevi
Copy link

jupevi commented Apr 21, 2022

You can add additional fields to the root response object by using the meta() magic method of SuccessResponseBuilder, e.g. in a controller method (the controller must use MakesResponses):

return $this->success()
             ->meta(['message' => 'Hello World!'])
             ->respond();

I don't think there's a way to add anything to the root object via a transformer class.

See: https://github.com/flugg/laravel-responder#adding-meta-data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants