From f2e58b6b1af67edc12528d1a9ea8e69905f00d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Tue, 13 Feb 2024 15:33:49 +0100 Subject: [PATCH] fix relatable query --- composer.lock | 30 +++++++++++++++--------------- src/Fields/Relation.php | 10 ++++++---- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/composer.lock b/composer.lock index 71392c54..0f6ed940 100644 --- a/composer.lock +++ b/composer.lock @@ -5328,16 +5328,16 @@ }, { "name": "larastan/larastan", - "version": "v2.8.1", + "version": "v2.9.0", "source": { "type": "git", "url": "https://github.com/larastan/larastan.git", - "reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022" + "reference": "35fa9cbe1895e76215bbe74571a344f2705fbe01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/larastan/larastan/zipball/b7cc6a29c457a7d4f3de90466392ae9ad3e17022", - "reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022", + "url": "https://api.github.com/repos/larastan/larastan/zipball/35fa9cbe1895e76215bbe74571a344f2705fbe01", + "reference": "35fa9cbe1895e76215bbe74571a344f2705fbe01", "shasum": "" }, "require": { @@ -5405,7 +5405,7 @@ ], "support": { "issues": "https://github.com/larastan/larastan/issues", - "source": "https://github.com/larastan/larastan/tree/v2.8.1" + "source": "https://github.com/larastan/larastan/tree/v2.9.0" }, "funding": [ { @@ -5425,7 +5425,7 @@ "type": "patreon" } ], - "time": "2024-01-08T09:11:17+00:00" + "time": "2024-02-13T11:49:22+00:00" }, { "name": "laravel/laravel", @@ -5433,12 +5433,12 @@ "source": { "type": "git", "url": "https://github.com/laravel/laravel.git", - "reference": "20261731467a6adc9393189d75b6e2362e1c31c0" + "reference": "d3287461e15862d1c7a8f10925988b4f1640d92b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/laravel/zipball/20261731467a6adc9393189d75b6e2362e1c31c0", - "reference": "20261731467a6adc9393189d75b6e2362e1c31c0", + "url": "https://api.github.com/repos/laravel/laravel/zipball/d3287461e15862d1c7a8f10925988b4f1640d92b", + "reference": "d3287461e15862d1c7a8f10925988b4f1640d92b", "shasum": "" }, "require": { @@ -5483,7 +5483,7 @@ "support": { "source": "https://github.com/laravel/laravel/tree/10.x" }, - "time": "2024-01-29T14:39:12+00:00" + "time": "2024-02-13T02:23:34+00:00" }, { "name": "laravel/pint", @@ -6084,16 +6084,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.57", + "version": "1.10.58", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + "reference": "a23518379ec4defd9e47cbf81019526861623ec2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a23518379ec4defd9e47cbf81019526861623ec2", + "reference": "a23518379ec4defd9e47cbf81019526861623ec2", "shasum": "" }, "require": { @@ -6142,7 +6142,7 @@ "type": "tidelift" } ], - "time": "2024-01-24T11:51:34+00:00" + "time": "2024-02-12T20:02:57+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Fields/Relation.php b/src/Fields/Relation.php index e1cb3741..bff0a917 100644 --- a/src/Fields/Relation.php +++ b/src/Fields/Relation.php @@ -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]); @@ -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();