laravel-responder icon indicating copy to clipboard operation
laravel-responder copied to clipboard

Include message in success response

Open LubySagia opened this issue 3 years ago • 1 comments

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

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

LubySagia avatar Jan 31 '22 12:01 LubySagia

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

jupevi avatar Apr 21 '22 12:04 jupevi