From a549c0ed75d1fcad91270cff66a607b59e561619 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Tue, 24 Dec 2024 11:54:11 +0300 Subject: [PATCH] filter search fix --- index.php | 5 +++++ src/EloquentDataProvider.php | 8 +++++++- src/models/User.php | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index cd5994e..5e54e32 100644 --- a/index.php +++ b/index.php @@ -55,6 +55,11 @@ try { 'class' => \Itguild\Tables\Filter\InputTextFilter::class ] ], + 'role' => [ + 'filter' => [ + 'class' => \Itguild\Tables\Filter\InputTextFilter::class + ], + ], 'created_at' => [ 'format' => 'date:d-m-Y', 'filter' => [ diff --git a/src/EloquentDataProvider.php b/src/EloquentDataProvider.php index 87743c9..8c3fe60 100644 --- a/src/EloquentDataProvider.php +++ b/src/EloquentDataProvider.php @@ -4,6 +4,7 @@ namespace Itguild\EloquentTable; use Exception; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\App; use itguild\forms\debug\Debug; class EloquentDataProvider @@ -61,7 +62,12 @@ class EloquentDataProvider if ($this->meta['searchParams']){ foreach ($this->meta['searchParams'] as $name => $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. '%'); + } } } } diff --git a/src/models/User.php b/src/models/User.php index 228b568..10b109e 100644 --- a/src/models/User.php +++ b/src/models/User.php @@ -21,7 +21,8 @@ class User extends Model { 'username' => 'Логин', 'email' => 'Email', 'created_at' => 'Создан', - 'updated_at' => 'Обновлен' + 'updated_at' => 'Обновлен', + 'role' => 'Роль' ]; } }