From 5526aece584c1d21bc6d1a3d9f294aaaa36b3c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Nabia=C5=82ek?= Date: Sat, 26 Nov 2016 10:21:34 +0100 Subject: [PATCH 1/2] Add whereKey method --- src/Illuminate/Database/Eloquent/Builder.php | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 5227c637abbe..3761f3936e6e 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -166,9 +166,7 @@ public function find($id, $columns = ['*']) return $this->findMany($id, $columns); } - $this->query->where($this->model->getQualifiedKeyName(), '=', $id); - - return $this->first($columns); + return $this->whereKey($id)->first($columns); } /** @@ -184,9 +182,22 @@ public function findMany($ids, $columns = ['*']) return $this->model->newCollection(); } - $this->query->whereIn($this->model->getQualifiedKeyName(), $ids); + return $this->whereKey($ids)->get($columns); + } - return $this->get($columns); + /** + * Add where clause with primary key to the query. + * + * @param mixed $id + * @return $this + */ + public function whereKey($id) + { + if (is_array($id)) { + $this->query->whereIn($this->model->getQualifiedKeyName(), $id); + return $this; + } + return $this->where($this->model->getQualifiedKeyName(), '=', $id); } /** From 7b54ffa8e270e809be05c9b1608d9bd383352850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Nabia=C5=82ek?= Date: Sat, 26 Nov 2016 10:29:40 +0100 Subject: [PATCH 2/2] Apply StyleCi patch --- src/Illuminate/Database/Eloquent/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 3761f3936e6e..a8aebdd416de 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -195,8 +195,10 @@ public function whereKey($id) { if (is_array($id)) { $this->query->whereIn($this->model->getQualifiedKeyName(), $id); + return $this; } + return $this->where($this->model->getQualifiedKeyName(), '=', $id); }