Created
August 27, 2016 10:33
-
-
Save jadjoubran/ee25de95ccde6c429a4c9967c422643e to your computer and use it in GitHub Desktop.
Laravel Response Macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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