From 169e27f47dd315d65b608f97297191a0cae9a949 Mon Sep 17 00:00:00 2001 From: Pasha Mesh Date: Wed, 21 Mar 2018 17:47:55 +0000 Subject: [PATCH] Added support of `whereIn` in `deleteWhere` method --- README.md | 21 +++++++++++++++++-- .../Repository/Eloquent/BaseRepository.php | 14 ++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5603b21e..0cd05686 100644 --- a/README.md +++ b/README.md @@ -435,8 +435,25 @@ Delete entry in Repository by multiple fields ```php $this->repository->deleteWhere([ //Default Condition = - 'state_id'=>'10', - 'country_id'=>'15', + 'state_id' => '10', + 'country_id' => '15', +]) +``` + +or full form to specify where condition + +```php +$this->repository->deleteWhere([ + ['state_id', '=', '10'], + ['country_id', '=', '15'], +]) +``` + +Delete entry in Repository by multiple field values (whereIn) + +```php +$this->repository->deleteWhere([ + 'status' => ['rejected', 'canceled'] ]) ``` diff --git a/src/Prettus/Repository/Eloquent/BaseRepository.php b/src/Prettus/Repository/Eloquent/BaseRepository.php index 7727091c..672e7dec 100644 --- a/src/Prettus/Repository/Eloquent/BaseRepository.php +++ b/src/Prettus/Repository/Eloquent/BaseRepository.php @@ -956,12 +956,20 @@ protected function applyCriteria() protected function applyConditions(array $where) { foreach ($where as $field => $value) { - if (is_array($value)) { + if (!is_array($value)) + { + $this->model = $this->model->where($field, '=', $value); + continue; + } + + if (is_numeric($field)) + { list($field, $condition, $val) = $value; $this->model = $this->model->where($field, $condition, $val); - } else { - $this->model = $this->model->where($field, '=', $value); + continue; } + + $this->model = $this->model->whereIn($field, $value); } }