Skip to content

Commit

Permalink
Merge pull request #70 from ibrunotome/patch-1
Browse files Browse the repository at this point in the history
Resolve #14 (query with case-insensitive)
  • Loading branch information
freekmurze authored Jun 5, 2018
2 parents 9807600 + 5863a95 commit 97bb90d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Filters/FiltersPartial.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@

class FiltersPartial implements Filter
{
public function __invoke(Builder $query, $value, string $property) : Builder
public function __invoke(Builder $query, $value, string $property): Builder
{
$sql = "LOWER({$property}) LIKE ?";

if (is_array($value)) {
return $query->where(function (Builder $query) use ($value, $property) {
return $query->where(function (Builder $query) use ($value, $sql) {
foreach ($value as $partialValue) {
$query->orWhere($property, 'LIKE', "%{$partialValue}%");
$partialValue = strtolower($partialValue);

$query->orWhereRaw($sql, ["%{$partialValue}%"]);
}
});
}

return $query->where($property, 'LIKE', "%{$value}%");
$value = strtolower($value);

return $query->whereRaw($sql, ["%{$value}%"]);
}
}

0 comments on commit 97bb90d

Please sign in to comment.