From c55e5c425f41f95486db9926fd29a2cf23453f58 Mon Sep 17 00:00:00 2001 From: Robin Dong Date: Thu, 11 Apr 2024 16:22:55 +0800 Subject: [PATCH 1/3] Support custom route key --- src/Http/Requests/Concerns/InteractWithRepositories.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Http/Requests/Concerns/InteractWithRepositories.php b/src/Http/Requests/Concerns/InteractWithRepositories.php index 71162649..1dfa4899 100644 --- a/src/Http/Requests/Concerns/InteractWithRepositories.php +++ b/src/Http/Requests/Concerns/InteractWithRepositories.php @@ -90,7 +90,8 @@ public function viaQuery(): Relation public function modelQuery(?string $repositoryId = null, ?string $uriKey = null): Builder|Relation { - return $this->newQuery($uriKey)->whereKey( + return $this->newQuery($uriKey)->where( + $this->model()->getRouteKeyName(), $repositoryId ?? $this->route('repositoryId') ); } From fb95a97521c1584e682b7d1409c4cda0b0c51f18 Mon Sep 17 00:00:00 2001 From: Robin Dong Date: Wed, 11 Sep 2024 15:11:18 +0800 Subject: [PATCH 2/3] fix(RepositoryCollection): Fix paginationLinks --- src/Repositories/RepositoryCollection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Repositories/RepositoryCollection.php b/src/Repositories/RepositoryCollection.php index cdb0fb12..c8ae04ff 100644 --- a/src/Repositories/RepositoryCollection.php +++ b/src/Repositories/RepositoryCollection.php @@ -18,10 +18,10 @@ public static function paginationLinks($paginated) 'first' => $paginated['first_page_url'] ?? null, 'last' => $paginated['last_page_url'] ?? null, 'prev' => array_key_exists('prev_page_url', $paginated) ? $paginated['prev_page_url'] : - collect(collect($paginated['links'])->firstWhere('label', 'Previous'))->get('url') + collect(collect($paginated['links'])->firstWhere('label', '« Previous'))->get('url') ?? null, - 'next' => array_key_exists('prev_page_url', $paginated) ? $paginated['prev_page_url'] : - collect(collect($paginated['links'])->firstWhere('label', 'Previous'))->get('url') + 'next' => array_key_exists('next_page_url', $paginated) ? $paginated['next_page_url'] : + collect(collect($paginated['links'])->firstWhere('label', 'Next »'))->get('url') ?? null, ]; } From 2817806bffdb8701695bbbe83ac734eaaa505e80 Mon Sep 17 00:00:00 2001 From: Robin Dong Date: Wed, 11 Sep 2024 17:41:30 +0800 Subject: [PATCH 3/3] Revert "Support custom route key" This reverts commit c55e5c425f41f95486db9926fd29a2cf23453f58. --- src/Http/Requests/Concerns/InteractWithRepositories.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Http/Requests/Concerns/InteractWithRepositories.php b/src/Http/Requests/Concerns/InteractWithRepositories.php index 1dfa4899..71162649 100644 --- a/src/Http/Requests/Concerns/InteractWithRepositories.php +++ b/src/Http/Requests/Concerns/InteractWithRepositories.php @@ -90,8 +90,7 @@ public function viaQuery(): Relation public function modelQuery(?string $repositoryId = null, ?string $uriKey = null): Builder|Relation { - return $this->newQuery($uriKey)->where( - $this->model()->getRouteKeyName(), + return $this->newQuery($uriKey)->whereKey( $repositoryId ?? $this->route('repositoryId') ); }