MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 259 forks source link

Search in Laravel 10 fails: mb_strtolower #572

Open jbajou opened 1 year ago

jbajou commented 1 year ago

Using the search input will result in the following error on Laravel 10:

mb_strtolower(): Argument #1 ($string) must be of type string, Illuminate\Database\Query\Expression given

Any idea ?

brunoalfred commented 1 year ago

Maybe this ‼️ https://github.com/MedicOneSystems/livewire-datatables/issues/567

andrecuellar commented 1 year ago

Maybe this ‼️ #567

It didn't fix that issue, I'm using that package

jbajou commented 1 year ago

I confirm, definitely not helping unfortunately...

andrecuellar commented 1 year ago

Maybe this is the problem https://laravel.com/docs/10.x/upgrade#database-expressions

jbajou commented 1 year ago

Agreed @andrecuellar the error lies on livewire-datatables/src/Http/Livewire/LivewireDatatable.php:1358, here:

foreach ($this->getColumnFilterStatement($i) as $column) {
                                $query->when(is_array($column), function ($query) use ($search, $column) {
                                    foreach ($column as $col) {
                                        $query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
                                    }
                                }, function ($query) use ($search, $column) {
                                    $query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $column . ') like ?', '%' . mb_strtolower($search) . '%');
                                });
                            }

I'll try to do a getValue() on it, maybe it will fix the issue.

alukardua1 commented 1 year ago

This error appears when the Column type is a callback. When setting up the output, it can be seen that $column outputs not a string, but Illuminate\Database\Query\Expression {#2078 ▼ // app\Http\Livewire\LivewireDatatable.php:1358

value: "CONCAT_WS('|lwdt|' ,COALESCE(summary_of_order_monitorings.order_number, ''), COALESCE(summary_of_order_monitorings.order_opening_date, ''), COALESCE(kd_engineers.number_summary_id, '')) ◀CONCAT_WS('|lwdt|' ,COALESCE(summary_of_order_monitorings.order_number, ''), COALESCE(summary_of_order_monitorings.order_opening_date, ''), COALESCE(kd_engi ▶"

}