Skip to content

Commit

Permalink
Set route resolver for FormRequest strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Oct 12, 2020
1 parent 4596426 commit ff13564
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Extracting/Strategies/BodyParameters/GetFromFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class GetFromFormRequest extends Strategy

public function __invoke(Route $route, ReflectionClass $controller, ReflectionFunctionAbstract $method, array $routeRules, array $alreadyExtractedData = []): array
{
return $this->getBodyParametersFromFormRequest($method);
return $this->getBodyParametersFromFormRequest($method, $route);
}

public function getBodyParametersFromFormRequest(ReflectionFunctionAbstract $method): array
public function getBodyParametersFromFormRequest(ReflectionFunctionAbstract $method, $route = null): array
{
foreach ($method->getParameters() as $param) {
$paramType = $param->getType();
Expand All @@ -58,8 +58,12 @@ public function getBodyParametersFromFormRequest(ReflectionFunctionAbstract $met
if (
(class_exists(LaravelFormRequest::class) && $parameterClass->isSubclassOf(LaravelFormRequest::class))
|| (class_exists(DingoFormRequest::class) && $parameterClass->isSubclassOf(DingoFormRequest::class))) {
/** @var LaravelFormRequest|DingoFormRequest\ $formRequest */
/** @var LaravelFormRequest|DingoFormRequest $formRequest */
$formRequest = new $parameterClassName;
// Set the route properly so it works for people who have code that checks for the route.
$formRequest->setRouteResolver(function () use ($route) {
return $route;
});
$bodyParametersFromFormRequest = $this->getBodyParametersFromValidationRules(
$this->getRouteValidationRules($formRequest),
$this->getCustomParameterData($formRequest)
Expand Down

0 comments on commit ff13564

Please sign in to comment.