Skip to content

Commit

Permalink
fix relatable query
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 13, 2024
1 parent 69865c8 commit f2e58b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ public function withRelatableQuery(Closure $callback): static
*/
public function resolveRelatableQuery(Request $request, Model $model): Builder
{
$query = $this->getRelation($model)->getRelated()->newQuery();
$query = $this->getRelation($model)
->getRelated()
->newQuery()
->with($this->with)
->withCount($this->withCount);

foreach (static::$scopes[static::class] ?? [] as $scope) {
$query = call_user_func_array($scope, [$request, $query, $model]);
Expand Down Expand Up @@ -511,9 +515,7 @@ public function paginate(Request $request, Model $model): LengthAwarePaginator
$relation = $this->getRelation($model);

return $this->resolveFilters($request)
->apply($request, $relation->getQuery())
->with($this->with)
->withCount($this->withCount)
->apply($request, $this->resolveRelatableQuery($request, $model))
->latest()
->paginate($request->input($this->getPerPageKey(), $request->isTurboFrameRequest() ? 5 : $relation->getRelated()->getPerPage()))
->withQueryString();
Expand Down

0 comments on commit f2e58b6

Please sign in to comment.