Enhance search column expression for pgsql prefix (#19694)

* Enhance search column expression for pgsql prefix

Added support for Laravel table prefix in PostgreSQL.

Signed-off-by: Max <mstaack@users.noreply.github.com>

* Update helpers.php

* Update helpersTest.php

---------

Signed-off-by: Max <mstaack@users.noreply.github.com>
Co-authored-by: Dan Harrin <git@danharrin.com>
This commit is contained in:
Max
2026-04-13 22:30:04 +01:00
committed by GitHub
co-authored by Dan Harrin
parent 10bad7f846
commit dafae5be8d
2 changed files with 25 additions and 0 deletions
+4
View File
@@ -245,6 +245,10 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) {
{
$driverName = $databaseConnection->getDriverName();
if ($driverName === 'pgsql' && str_contains($column, '.')) {
$column = $databaseConnection->getTablePrefix() . $column;
}
$column = match ($driverName) {
'pgsql' => (
str($column)->contains('->')
+21
View File
@@ -111,6 +111,7 @@ it('will generate a column expression for Postgres with colons in the table name
$databaseConnection = Mockery::mock(Connection::class);
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
$databaseConnection->shouldReceive('getTablePrefix')->andReturn('');
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
$grammar = new PostgresGrammar($databaseConnection);
@@ -125,6 +126,26 @@ it('will generate a column expression for Postgres with colons in the table name
['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'],
]);
it('will generate a search column expression for Postgres with a table prefix', function (string $column, string $expectedExpression): void {
$isSearchForcedCaseInsensitive = true;
$databaseConnection = Mockery::mock(Connection::class);
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
$databaseConnection->shouldReceive('getTablePrefix')->andReturn('app_');
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
$grammar = new PostgresGrammar($databaseConnection);
$actualExpression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
expect($actualExpression->getValue($grammar))
->toBe($expectedExpression);
})
->with([
['posts.title', 'lower("app_posts"."title"::text)'],
['posts.data->name', "lower(\"app_posts\".\"data\"->>'name'::text)"],
]);
it('will generate a JSON search column expression for Postgres with explicit ->> operator', function (): void {
$column = 'data->>name';
$isSearchForcedCaseInsensitive = true;