Compare commits

...

3 Commits

Author SHA1 Message Date
a549c0ed75 filter search fix 2024-12-24 11:54:11 +03:00
72f528e75d search params 2024-12-23 17:24:30 +03:00
13b54a563d search prefix 2024-12-23 16:52:20 +03:00
5 changed files with 27 additions and 2047 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
.env
vendor
composer.lock

2044
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,9 @@ try {
'currentPage' => 1,
'perPage' => 3,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
'baseUrl' => "",
'searchPrefix' => '',
'searchParams' => $_GET,
'filters' => ["email"]
]));
$table->columns([
@ -53,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' => [

View File

@ -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
@ -48,6 +49,8 @@ class EloquentDataProvider
$this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table;
$this->meta['params'] = $options['params'] ?? [];
$this->meta['actions'] = $options['actions'] ?? [];
$this->meta['searchPrefix'] = $options['searchPrefix'] ?? '/search';
$this->meta['searchParams'] = $options['searchParams'] ?? [];
$this->meta['showFiltersRow'] = $options['showFiltersRow'] ?? true;
$this->filters = $options['filters'] ?? [];
$this->createQuery();
@ -56,6 +59,18 @@ class EloquentDataProvider
public function createQuery(): void
{
if ($this->meta['searchParams']){
foreach ($this->meta['searchParams'] as $name => $param){
if (array_key_exists($name, $this->meta['columns']) && !empty($param)){
if (is_numeric($param)){
$this->queryBuilder->where($name, $this->meta['searchParams'][$name]);
}
elseif (is_string($param)){
$this->queryBuilder->where($name,'like', '%' . $param. '%');
}
}
}
}
if ($this->currentPage > 1) {
$this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage);
} else {

View File

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