From 5cea8626f4ba41e0b278bb9c01ea80247d9dc8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 17 Aug 2023 00:15:15 +0200 Subject: [PATCH] Make default ID convigurable in Query\Builder::find, forPageBeforeId and forPageAfterId --- src/Illuminate/Database/Query/Builder.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 0da469faa8bb..aa0cf06a0ed7 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -2456,11 +2456,12 @@ public function forPage($page, $perPage = 15) * * @param int $perPage * @param int|null $lastId - * @param string $column + * @param string|null $column * @return $this */ - public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id') + public function forPageBeforeId($perPage = 15, $lastId = 0, $column = null) { + $column ??= $this->defaultKeyName(); $this->orders = $this->removeExistingOrdersFor($column); if (! is_null($lastId)) { @@ -2476,11 +2477,12 @@ public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id') * * @param int $perPage * @param int|null $lastId - * @param string $column + * @param string|null $column * @return $this */ - public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id') + public function forPageAfterId($perPage = 15, $lastId = 0, $column = null) { + $column ??= $this->defaultKeyName(); $this->orders = $this->removeExistingOrdersFor($column); if (! is_null($lastId)) { @@ -2655,7 +2657,7 @@ public function toRawSql() */ public function find($id, $columns = ['*']) { - return $this->where('id', '=', $id)->first($columns); + return $this->where($this->defaultKeyName(), '=', $id)->first($columns); } /**