Skip to content

Commit

Permalink
Fix relation search (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev authored Nov 6, 2024
1 parent 75693ea commit 703913b
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 703913b

Please sign in to comment.