diff --git a/src/Prettus/Repository/Criteria/RequestCriteria.php b/src/Prettus/Repository/Criteria/RequestCriteria.php index 79734add..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,18 +106,19 @@ 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($field,$value); + $query->whereIn($$modelTableName.'.'.$field,$value,'and',$not); }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 { if($condition === 'in'){ - $query->whereIn($modelTableName.'.'.$field,$value); + $query->whereIn($modelTableName.'.'.$field,$value,'and',$not); }elseif($condition === 'between'){ $query->whereBetween($modelTableName.'.'.$field,$value); }else{ @@ -126,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{ @@ -135,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{