Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. namespace AppHttpControllersMyAPI;
  2. use IlluminateHttpRequest;
  3. use AppHttpControllersController;
  4. class MyAPIController extends Controller {
  5.  
  6. const acceptMethod = ['GET','POST','PUT','DELETE']
  7.  
  8. public function handler(Request $request) {
  9. $acceptMethod = self::acceptMethod;
  10. $ctrl = new PromotionController;
  11. $method = $request->method()
  12.  
  13. // This is my question :((
  14. if ($method == 'GET')
  15. $ctrl::read($request);
  16. if ($method == 'GET')
  17. $ctrl::post($request);
  18. $ctrl::put($request);
  19. ...
  20.  
  21. //I want to be like this :
  22. foreach($acceptMethod as $method) {
  23. // Not work
  24. $ctrl::($method)($request);
  25. }
  26.  
  27.  
  28. }
  29.  
  30. public static function read(Request $request) {
  31. return something;
  32. }
  33.  
  34. public static function post(Request $request) {
  35. return ...;
  36. }
  37.  
  38. public static function put(Request $request) {
  39. return ...;
  40. }
  41.  
  42. public static function delete(Request $request) {
  43. return ...;
  44. }
  45.  
  46. }
  47.  
  48. if ($method == 'get')
  49. $ctrl::read($request);
  50. if ($method == 'post')
  51. $ctrl::post($request);
  52. $ctrl::put($request);
  53.  
  54. $acceptMethod = ['GET','POST','PUT','DELETE'];
  55. foreach($acceptMethod as $functionName) {
  56. // Not work
  57. $ctrl::$functionName($request);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement