From 73dc2a16047172de8bc2c0000bfa6db75075e374 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 24 Dec 2023 11:38:23 +0330 Subject: [PATCH 1/2] for prevent query exception ambiguous --- src/Prettus/Repository/Criteria/RequestCriteria.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Prettus/Repository/Criteria/RequestCriteria.php b/src/Prettus/Repository/Criteria/RequestCriteria.php index 79734add..87b7fc41 100644 --- a/src/Prettus/Repository/Criteria/RequestCriteria.php +++ b/src/Prettus/Repository/Criteria/RequestCriteria.php @@ -102,12 +102,13 @@ public function apply($model, RepositoryInterface $repository) if (!is_null($value)) { if(!is_null($relation)) { $query->whereHas($relation, function($query) use($field,$condition,$value) { + $modelTableName = $query->getModel()->getTable(); if($condition === 'in'){ - $query->whereIn($field,$value); + $query->whereIn($$modelTableName.'.'.$field,$value); }elseif($condition === 'between'){ - $query->whereBetween($field,$value); + $query->whereBetween($$modelTableName.'.'.$field,$value); }else{ - $query->where($field,$condition,$value); + $query->where($$modelTableName.'.'.$field,$condition,$value); } }); } else { From ec990bbd136d1889dfdbe801bc5e08135eede95d Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 1 Jan 2024 17:59:08 +0330 Subject: [PATCH 2/2] add where not in support in request criteria --- .../Repository/Criteria/RequestCriteria.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Prettus/Repository/Criteria/RequestCriteria.php b/src/Prettus/Repository/Criteria/RequestCriteria.php index 87b7fc41..1cc6c95b 100644 --- a/src/Prettus/Repository/Criteria/RequestCriteria.php +++ b/src/Prettus/Repository/Criteria/RequestCriteria.php @@ -85,6 +85,11 @@ public function apply($model, RepositoryInterface $repository) $field = array_pop($explode); $relation = implode('.', $explode); } + $not = false; + if ($condition === 'notin') { + $not = true; + $condition = 'in'; + } if($condition === 'in'){ $value = explode(',',$value); if( trim($value[0]) === "" || $field == $value[0]){ @@ -101,10 +106,10 @@ public function apply($model, RepositoryInterface $repository) if ( $isFirstField || $modelForceAndWhere ) { if (!is_null($value)) { if(!is_null($relation)) { - $query->whereHas($relation, function($query) use($field,$condition,$value) { + $query->whereHas($relation, function($query) use($field,$condition,$value,$not) { $modelTableName = $query->getModel()->getTable(); if($condition === 'in'){ - $query->whereIn($$modelTableName.'.'.$field,$value); + $query->whereIn($$modelTableName.'.'.$field,$value,'and',$not); }elseif($condition === 'between'){ $query->whereBetween($$modelTableName.'.'.$field,$value); }else{ @@ -113,7 +118,7 @@ public function apply($model, RepositoryInterface $repository) }); } else { if($condition === 'in'){ - $query->whereIn($modelTableName.'.'.$field,$value); + $query->whereIn($modelTableName.'.'.$field,$value,'and',$not); }elseif($condition === 'between'){ $query->whereBetween($modelTableName.'.'.$field,$value); }else{ @@ -127,7 +132,7 @@ public function apply($model, RepositoryInterface $repository) if(!is_null($relation)) { $query->orWhereHas($relation, function($query) use($field,$condition,$value) { if($condition === 'in'){ - $query->whereIn($field,$value); + $query->whereIn($field,$value,'and',$not); }elseif($condition === 'between'){ $query->whereBetween($field, $value); }else{ @@ -136,7 +141,7 @@ public function apply($model, RepositoryInterface $repository) }); } else { if($condition === 'in'){ - $query->orWhereIn($modelTableName.'.'.$field, $value); + $query->orWhereIn($modelTableName.'.'.$field, $value,'and',$not); }elseif($condition === 'between'){ $query->whereBetween($modelTableName.'.'.$field,$value); }else{