Skip to content

Commit

Permalink
Fix search join (#1705)
Browse files Browse the repository at this point in the history
* Fix search join

* fix search join
  • Loading branch information
luanfreitasdev authored Oct 1, 2024
1 parent 36fa962 commit 98690cd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/DataSource/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,26 @@ public function filterContains(): Builder
$query->orWhereRaw($sqlRaw . ' ' . Sql::like($query) . ' ?', ["%{$search}%"]);
}

if ($hasColumn && blank(data_get($column, 'searchableRaw'))) {
try {
try {
if ($hasColumn && blank(data_get($column, 'searchableRaw'))) {
$columnType = $this->getColumnType($table, $field);

/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line */
$driverName = $query->getConnection()->getConfig('driver');

if ($columnType === 'json' && strtolower($driverName) !== 'pgsql') {
$query->orWhereRaw("LOWER(`{$table}`.`{$field}`)" . Sql::like($query) . ' ?', ["%{$search}%"]);
} else {
$query->orWhere("{$table}.{$field}", Sql::like($query), "%{$search}%");
}
} catch (\Throwable) {
$query->orWhere("{$table}.{$field}", Sql::like($query), "%{$search}%");
}
} catch (\Throwable) {
$query
->when(
$table,
fn (EloquentBuilder|QueryBuilder $query) => $query->orWhere("{$table}.{$field}", Sql::like($query), "%{$search}%"),
fn (EloquentBuilder|QueryBuilder $query) => $query->orWhere($field, Sql::like($query), "%{$search}%")
);
}
});
});
Expand Down

0 comments on commit 98690cd

Please sign in to comment.