Skip to content

Commit

Permalink
Add in condition to requestCriteria (andersao#741)
Browse files Browse the repository at this point in the history
* Update repository.php

* added In criteria
  • Loading branch information
bsormagec authored Dec 19, 2020
1 parent c80a334 commit f2a4b23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/Prettus/Repository/Criteria/RequestCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,37 @@ public function apply($model, RepositoryInterface $repository)
if (!is_null($value)) {
if(!is_null($relation)) {
$query->whereHas($relation, function($query) use($field,$condition,$value) {
$query->where($field,$condition,$value);
if($condition === 'in'){
$query->whereIn($field,explode(',',$value));
}else{
$query->where($field,$condition,$value);
}
});
} else {
$query->where($modelTableName.'.'.$field,$condition,$value);
if($condition === 'in'){
$query->whereIn($modelTableName.'.'.$field,explode(',',$value));
}else{
$query->where($modelTableName.'.'.$field,$condition,$value);
}
}
$isFirstField = false;
}
} else {
if (!is_null($value)) {
if(!is_null($relation)) {
$query->orWhereHas($relation, function($query) use($field,$condition,$value) {
$query->where($field,$condition,$value);
if($condition === 'in'){
$query->whereIn($field,explode(',',$value));
}else{
$query->where($field,$condition,$value);
}
});
} else {
$query->orWhere($modelTableName.'.'.$field, $condition, $value);
if($condition === 'in'){
$query->orWhereIn($modelTableName.'.'.$field, explode(',',$value));
}else{
$query->orWhere($modelTableName.'.'.$field, $condition, $value);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/resources/config/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
*/
'acceptedConditions' => [
'=',
'like'
'like',
'in'
],
/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit f2a4b23

Please sign in to comment.