Skip to content

Commit

Permalink
Fix relation search
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Nov 1, 2024
1 parent 125d6d4 commit 6cdaba4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/DataSource/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,20 @@ public function filterContains(): Builder

$hasColumn = isset($columnList[$field]);

$query->when(
$hasColumn && $table,
fn (EloquentBuilder|QueryBuilder $query) => $query->orWhere("{$table}.{$field}", Sql::like($query), "%{$search}%"),
fn (EloquentBuilder|QueryBuilder $query) => $query->orWhere($field, Sql::like($query), "%{$search}%")
);
try {
$query
->when(
$hasColumn && $table,
fn (EloquentBuilder|QueryBuilder $query) => $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}%")
);
}
});

return $query;
Expand Down

0 comments on commit 6cdaba4

Please sign in to comment.