Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace AppHttpControllersMyAPI;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- class MyAPIController extends Controller {
- const acceptMethod = ['GET','POST','PUT','DELETE']
- public function handler(Request $request) {
- $acceptMethod = self::acceptMethod;
- $ctrl = new PromotionController;
- $method = $request->method()
- // This is my question :((
- if ($method == 'GET')
- $ctrl::read($request);
- if ($method == 'GET')
- $ctrl::post($request);
- $ctrl::put($request);
- ...
- //I want to be like this :
- foreach($acceptMethod as $method) {
- // Not work
- $ctrl::($method)($request);
- }
- }
- public static function read(Request $request) {
- return something;
- }
- public static function post(Request $request) {
- return ...;
- }
- public static function put(Request $request) {
- return ...;
- }
- public static function delete(Request $request) {
- return ...;
- }
- }
- if ($method == 'get')
- $ctrl::read($request);
- if ($method == 'post')
- $ctrl::post($request);
- $ctrl::put($request);
- $acceptMethod = ['GET','POST','PUT','DELETE'];
- foreach($acceptMethod as $functionName) {
- // Not work
- $ctrl::$functionName($request);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement