diff --git a/src/Concerns/WithAttributes.php b/src/Concerns/WithAttributes.php index 1cc3746..860ec0a 100644 --- a/src/Concerns/WithAttributes.php +++ b/src/Concerns/WithAttributes.php @@ -5,6 +5,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Arr; use Lorisleiva\Actions\AttributeValidator; +use ReflectionMethod; +use ReflectionParameter; trait WithAttributes { @@ -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); }