Skip to content

Commit

Permalink
fix: do not filter belongs to many fields (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryk authored Feb 11, 2023
1 parent 20749fc commit f7942c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Fields/Concerns/Attachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function initializePivot(RestifyRequest $request, $relationship, $related
]);
}

$fields = $this->collectPivotFields()->filter(fn ($pivotField) => $request->has($pivotField->attribute))->values();
$fields = $this->collectPivotFields()->values();

$repository = $request->repository();

Expand Down
6 changes: 5 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ function rest(...$models): Serializer
{
$models = collect($models)->flatten();

$repository = Restify::repositoryForModel(get_class($models->first())) ?? Repository::class;
if ($models->first()) {
$repository = Restify::repositoryForModel(get_class($models->first())) ?? Repository::class;
} else {
$repository = Repository::class;
}

return (new Serializer(app($repository)))
->models(collect($models));
Expand Down

0 comments on commit f7942c6

Please sign in to comment.