filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.09k stars 2.83k forks source link

SpatieTranslatable Listing column searchable give exception in sql query #7537

Closed taha-hespress closed 1 year ago

taha-hespress commented 1 year ago

Package

filament/filament

Package Version

v3.0.11

Laravel Version

v10.17.1

Livewire Version

v3.0.0-beta.7

PHP Version

PHP 8.2.3

Problem description

with fresh install of filament + Spatie Translatable Plugin, when trying to search in table with a translatable column, give this error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'json_extract(name, "$.en")' in 'where clause' SELECT count(*) AS aggregate FROM patients WHERE (json_extract(name, "$.en") LIKE %engl% OR type LIKE %engl%)

Potential fix found

update in line 102 /filament/spatie-laravel-translatable-plugin/src/SpatieLaravelTranslatableContentDriver.php and make the column inside Expression $caseAwareSearchColumn = $isCaseInsensitivityForced ? new Expression("lower({$column})") : $column;

to $caseAwareSearchColumn = $isCaseInsensitivityForced ? new Expression("lower({$column})") : new Expression($column);

Expected behavior

the table search according to the local selected

Steps to reproduce

  1. install Filament Spatie Translatable Plugin
  2. make a translatable column searchable in table method in resource class
  3. make a search

Reproduction repository

https://github.com/taha-hespress/filament-translatable-search-bug

Relevant log output

No response

ousid commented 10 months ago

@danharrin This issue still occur, when using Spatie Translatable, then tries to search on a table:

Error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'json_extract(name, "$.en")' in 'where clause'

----

SELECT
  count(*) AS aggregate
FROM
  `products`
WHERE
  (`products`.`deleted_at` IS NULL)
  AND (
    `json_extract(name, "$`.`en")` LIKE % a %
    OR `initial_price` LIKE % a %
    OR `quantity` LIKE % a %
    OR `json_extract(name, "$`.`en")` LIKE % a %
  )

Packages Info

Package filament/filament

Package Version v3.0.93

Laravel Version v10.31.0

Livewire Version v3.1.0

PHP Version V 8.2.11

mstfkhazaal commented 10 months ago

@danharrin this issue still occur

danharrin commented 10 months ago

With the same reproduction repo?

mstfkhazaal commented 10 months ago

With the same reproduction repo?

no

danharrin commented 10 months ago

We need a new issue with a new repo then

Saifallak commented 10 months ago

having same issue too, as https://github.com/filamentphp/filament/issues/7537#issuecomment-1805960402

greatsami commented 10 months ago

I'm facing the same issue

danharrin commented 10 months ago

Since this issue has been reported as resolved (https://github.com/filamentphp/filament/issues/7537#issuecomment-1807751819), please see my comment above and open a new issue with a new reproduction repp