Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TitasGailius committed Mar 15, 2019
1 parent 9efd0bd commit dc04326
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/SearchesRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,27 @@ protected static function applyRelationSearch(Builder $query, string $search): B
protected static function searchQueryApplier(array $columns, string $search): Closure
{
return function ($query) use ($columns, $search) {

$model = $query->getModel();

$connectionType = $query->getModel()->getConnection()->getDriverName();

$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';
$operator = static::operator($query);

foreach ($columns as $column) {
$query->orWhere($model->qualifyColumn($column), $likeOperator, '%' . $search . '%');
$query->orWhere($model->qualifyColumn($column), $operator, '%'.$search.'%');
}
};
}

/**
* Resolve the query operator.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return string
*/
protected static function operator(Builder $query): string
{
if ($query->getModel()->getConnection()->getDriverName() === 'pgsql') {
return 'ILIKE';
}

return 'LIKE';
}
}

0 comments on commit dc04326

Please sign in to comment.