diff --git a/src/DataSource/Builder.php b/src/DataSource/Builder.php index af637779..9ae6f633 100644 --- a/src/DataSource/Builder.php +++ b/src/DataSource/Builder.php @@ -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;