Skip to content

Commit

Permalink
fix: pass only required parameters of handle method
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz committed Aug 11, 2023
1 parent 0c5484a commit f8b2be4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Concerns/WithAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Lorisleiva\Actions\AttributeValidator;
use ReflectionMethod;
use ReflectionParameter;

trait WithAttributes
{
Expand All @@ -20,6 +22,15 @@ public static function runWithAttributes(...$arguments)
$action = static::make();

$action->fill($arguments)->validateAttributes();

$requiredArguments = collect((new ReflectionMethod($action, 'handle'))->getParameters())
->filter(function (ReflectionParameter $parameter) use ($arguments) {
return isset($arguments[$parameter->name]);
})
->map(function (ReflectionParameter $parameter) use ($arguments) {
return $arguments[$parameter->name];
})
->toArray();

return $action->handle(...$arguments);
}
Expand Down

0 comments on commit f8b2be4

Please sign in to comment.