Skip to content

Instantly share code, notes, and snippets.

@jadjoubran
Created August 27, 2016 10:33
Show Gist options
  • Save jadjoubran/ee25de95ccde6c429a4c9967c422643e to your computer and use it in GitHub Desktop.
Save jadjoubran/ee25de95ccde6c429a4c9967c422643e to your computer and use it in GitHub Desktop.
Laravel Response Macros
<?php
class ResponseMacroServiceProvider extends ServiceProvider
{
public function boot()
{
Response::macro('success', function ($data) {
return Response::json([
'errors' => false,
'data' => $data,
]);
});
Response::macro('error', function ($message, $status = 400) {
return Response::json([
'errors' => true,
'message' => $message,
], $status);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment