filter search fix

This commit is contained in:
Kavalar 2024-12-24 11:54:11 +03:00
parent 72f528e75d
commit a549c0ed75
3 changed files with 14 additions and 2 deletions

View File

@ -55,6 +55,11 @@ try {
'class' => \Itguild\Tables\Filter\InputTextFilter::class 'class' => \Itguild\Tables\Filter\InputTextFilter::class
] ]
], ],
'role' => [
'filter' => [
'class' => \Itguild\Tables\Filter\InputTextFilter::class
],
],
'created_at' => [ 'created_at' => [
'format' => 'date:d-m-Y', 'format' => 'date:d-m-Y',
'filter' => [ 'filter' => [

View File

@ -4,6 +4,7 @@ namespace Itguild\EloquentTable;
use Exception; use Exception;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use itguild\forms\debug\Debug; use itguild\forms\debug\Debug;
class EloquentDataProvider class EloquentDataProvider
@ -61,7 +62,12 @@ class EloquentDataProvider
if ($this->meta['searchParams']){ if ($this->meta['searchParams']){
foreach ($this->meta['searchParams'] as $name => $param){ foreach ($this->meta['searchParams'] as $name => $param){
if (array_key_exists($name, $this->meta['columns']) && !empty($param)){ if (array_key_exists($name, $this->meta['columns']) && !empty($param)){
$this->queryBuilder->where($name, $this->meta['searchParams'][$name]); if (is_numeric($param)){
$this->queryBuilder->where($name, $this->meta['searchParams'][$name]);
}
elseif (is_string($param)){
$this->queryBuilder->where($name,'like', '%' . $param. '%');
}
} }
} }
} }

View File

@ -21,7 +21,8 @@ class User extends Model {
'username' => 'Логин', 'username' => 'Логин',
'email' => 'Email', 'email' => 'Email',
'created_at' => 'Создан', 'created_at' => 'Создан',
'updated_at' => 'Обновлен' 'updated_at' => 'Обновлен',
'role' => 'Роль'
]; ];
} }
} }