Skip to content

Commit

Permalink
Action improvement (#417)
Browse files Browse the repository at this point in the history
* Prevent action handlers from being called when iterating over non-actionable fields

* Replacement fix

* Only handle actions for fields present in request

* Add filter for fields in request
  • Loading branch information
dsindrilaru authored Aug 30, 2021
1 parent a191c46 commit f6693e3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Fields/FieldCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function forStore(RestifyRequest $request, $repository): self
public function withActions(RestifyRequest $request, $repository): self
{
return $this
->inRequest($request)
->filter(fn (Field $field) => $field->isActionable())
->values();
}
Expand Down Expand Up @@ -152,4 +153,11 @@ public function findFieldByAttribute($attribute, $default = null)

return null;
}

public function inRequest(RestifyRequest $request): self
{
return $this
->filter(fn (Field $field) => $request->has($field->attribute) || $request->hasFile($field->attribute))
->values();
}
}

0 comments on commit f6693e3

Please sign in to comment.