diff --git a/composer.json b/composer.json index 37cba67..4961537 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,7 @@ "tymon/jwt-auth": "^1.0", "illuminate/support": "^6 || ^5.8", "webpatser/laravel-uuid": "^3.0", - "ramsey/uuid": "^3.0", - "atehnix/laravel-stubs": "~6.0" + "ramsey/uuid": "^3.0" }, "require-dev": { "ext-json": "*", diff --git a/src/Http/Controllers/Features/RestfulControllerTrait.php b/src/Http/Controllers/Features/RestfulControllerTrait.php index 29f2f57..caa792e 100644 --- a/src/Http/Controllers/Features/RestfulControllerTrait.php +++ b/src/Http/Controllers/Features/RestfulControllerTrait.php @@ -77,12 +77,28 @@ protected function isRequestBodyACollection(Request $request) */ protected function shouldTransform() { - // If we are not called by this function, then we are not called by the router - if (debug_backtrace()[2]['function'] != 'call_user_func_array') { - return false; + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + + // We're going to check up to the top 20 calls (first 3-5 should be more than enough for almost any situation) + $numberOfCallsToCheck = 20; + $callsToCheck = []; + + for ($i = 0; $i < sizeof($trace) && $numberOfCallsToCheck > 0; ++$i) { + // We only want function calls + if (array_key_exists('file', $trace[$i])) { + $callsToCheck[] = $trace[$i]; + --$numberOfCallsToCheck; + } } - return true; + // This should work for both the new and old scenarios + if (basename($callsToCheck[1]['file']) == 'Controller.php' && + basename($callsToCheck[2]['file']) == 'ControllerDispatcher.php' && + $callsToCheck[2]['function'] == 'callAction') { + return true; + } + + return false; } /**