Skip to content

Commit bb9359b

Browse files
authored
Take actionable fields into account when calling patch method (#547)
* Take actionable fields into account when calling patch method * check for authorization to patch instead of update
1 parent 6f962e8 commit bb9359b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Repositories/Repository.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,14 +713,15 @@ public function update(RestifyRequest $request, $repositoryId)
713713

714714
public function patch(RestifyRequest $request, $repositoryId)
715715
{
716-
DB::transaction(function () use ($request) {
717-
$keys = $request->json()->keys();
716+
$keys = $request->json()->keys();
718717

718+
DB::transaction(function () use ($request, $keys) {
719719
$fields = $this->collectFields($request)
720720
->filter(
721721
fn (Field $field) => in_array($field->attribute, $keys),
722722
)
723723
->forUpdate($request, $this)
724+
->withoutActions($request, $this)
724725
->authorizedPatch($request)
725726
->merge($this->collectFields($request)->forBelongsTo($request));
726727

@@ -739,6 +740,16 @@ public function patch(RestifyRequest $request, $repositoryId)
739740
fn (Field $field) => $field->invokeAfter($request, $this->resource)
740741
);
741742

743+
$this
744+
->collectFields($request)
745+
->filter(
746+
fn (Field $field) => in_array($field->attribute, $keys),
747+
)
748+
->forUpdate($request, $this)
749+
->withActions($request, $this)
750+
->authorizedPatch($request)
751+
->each(fn (Field $field) => $field->actionHandler->handle($request, $this->resource));
752+
742753
return data($this->serializeForShow($request));
743754
}
744755

0 commit comments

Comments
 (0)