Skip to content

Commit

Permalink
Fixed search criteria. Its conditions must be within parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrián Pardellas Blunier committed Sep 19, 2016
1 parent d88c3d7 commit 073799d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Repository/Criteria/SearchCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ public function __construct(array $columns, $queryString)

public function apply($model, Repository $repository)
{
$firstColumn = array_shift($this->columns);
$query = $model->where(function ($query) use ($repository) {
$firstColumn = array_shift($this->columns);

if (strpos($firstColumn, '.')) {
$query = $this->setRelationFieldCondition($model, $firstColumn, false);
} else {
$query = $model->where($firstColumn, 'LIKE', '%'.$this->queryString.'%');
}

foreach ($this->columns as $column) {
if (strpos($column, '.')) {
$query = $this->setRelationFieldCondition($query, $column);
if (strpos($firstColumn, '.')) {
$query = $this->setRelationFieldCondition($query, $firstColumn, false);
} else {
$query->orWhere($column, 'LIKE', '%'.$this->queryString.'%');
$query = $query->where($firstColumn, 'LIKE', '%'.$this->queryString.'%');
}
}

foreach ($this->columns as $column) {
if (strpos($column, '.')) {
$query = $this->setRelationFieldCondition($query, $column);
} else {
$query->orWhere($column, 'LIKE', '%'.$this->queryString.'%');
}
}
});

return $query;
}
Expand Down

0 comments on commit 073799d

Please sign in to comment.