diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index c237d6ff19..62c72e6339 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -163,22 +163,25 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) { { $driverName = $databaseConnection->getDriverName(); - if (Str::lower($column) !== $column) { - $column = match ($driverName) { - 'pgsql' => (string) str($column)->wrap('"'), - default => $column, - }; - } - $column = match ($driverName) { - 'pgsql' => (str($column)->contains('->') - ? str($column) - ->beforeLast('->') + 'pgsql' => ( + str($column)->contains('->') + ? str( + str($column) + ->beforeLast('->') + ->explode('.') + ->map(fn (string $part) => str($part)->wrap('"')) + ->implode('.') + ) ->append('->>') ->append("'") ->append(str($column)->afterLast('->')) ->append("'") - : $column) . '::text', + : str($column) + ->explode('.') + ->map(fn (string $part) => str($part)->wrap('"')) + ->implode('.') + ) . '::text', default => $column, }; diff --git a/tests/src/Support/helpersTest.php b/tests/src/Support/helpersTest.php index 627373d5ea..a5c8d2a29a 100644 --- a/tests/src/Support/helpersTest.php +++ b/tests/src/Support/helpersTest.php @@ -75,5 +75,24 @@ it('will generate json search column expression for pgsql', function () { $expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection); expect($expression->getValue($grammar)) - ->toBe("lower(data->>'name'::text)"); + ->toBe("lower(\"data\"->>'name'::text)"); }); + +it('will generate column expression for pgsql with colons in the name', function (string $column, string $text) { + $isSearchForcedCaseInsensitive = true; + + $databaseConnection = Mockery::mock(Connection::class); + $databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql'); + $databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null); + + $grammar = new PostgresGrammar($databaseConnection); + + $expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection); + + expect($expression->getValue($grammar)) + ->toBe($text); +}) + ->with([ + ['blog:posts.title', 'lower("blog:posts"."title"::text)'], + ['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'], + ]);