ResponseMacroServiceProvider.php 704 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Support\Facades\Response;
  5. class ResponseMacroServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * Register services.
  9. *
  10. * @return void
  11. */
  12. public function register()
  13. {
  14. //
  15. }
  16. /**
  17. * Bootstrap services.
  18. *
  19. * @return void
  20. */
  21. public function boot()
  22. {
  23. Response::macro('horesp', function ($code = '0000', $data = null, $msg = null) {
  24. $content = array(
  25. 'code' => $code,
  26. 'data' => $data,
  27. 'msg' => $msg
  28. );
  29. return response()->json($content);
  30. });
  31. }
  32. }