Last active
March 10, 2017 16:01
-
-
Save princealikhan/30a0dfdbdb233a02595007756eebb1ef to your computer and use it in GitHub Desktop.
Response Macro Laravel
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
'providers' => [ | |
App\Providers\ResponseMacroServiceProvider::class, | |
] |
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 | |
namespace App\Providers; | |
use Response; | |
use Illuminate\Support\ServiceProvider; | |
class ResponseMacroServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Response::macro('success', function ($data) { | |
return Response::json([ | |
'data' => $data, | |
'status_update' => array( | |
'status_code' => 'success', | |
'msg' => 'Your Message' | |
), | |
]); | |
}); | |
Response::macro('error', function ($message, $status = 400) { | |
return Response::json([ | |
'message' => $status.' error', | |
'errors' => [ | |
'message' => [$message], | |
], | |
'status_code' => $status, | |
], $status); | |
}); | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment