8 Commits

Author SHA1 Message Date
7cdbff5ce9 fillable 2025-01-27 12:30:05 +03:00
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
a3b5f5fa0c fix filter row 2024-12-23 15:05:02 +03:00
708045664c example update 2024-08-29 13:15:41 +03:00
d3cda0bd8f merge 2024-08-29 12:46:28 +03:00
3bb6ae8b07 example update 2024-08-29 12:44:40 +03:00
6 changed files with 42 additions and 1986 deletions

3
.gitignore vendored
View File

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

View File

@ -2,7 +2,7 @@
"name": "itguild/eloquent-table", "name": "itguild/eloquent-table",
"type": "library", "type": "library",
"require": { "require": {
"itguild/tables": "^0.1.9" "itguild/tables": "^1.0"
}, },
"require-dev": { "require-dev": {
"illuminate/database": "^12.0@dev", "illuminate/database": "^12.0@dev",

1975
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -44,16 +44,28 @@ try {
'currentPage' => 1, 'currentPage' => 1,
'perPage' => 3, 'perPage' => 3,
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user" 'baseUrl' => "",
'searchPrefix' => '',
'searchParams' => $_GET,
'filters' => ["email"]
])); ]));
$table->columns([ $table->columns([
'created_at' => function ($data) { 'username' => [
if (!$data){ 'filter' => [
return null; 'class' => \Itguild\Tables\Filter\InputTextFilter::class
} ]
],
return (new DateTimeImmutable($data))->format("d-m-Y"); 'role' => [
}, 'filter' => [
'class' => \Itguild\Tables\Filter\InputTextFilter::class
],
],
'created_at' => [
'format' => 'date:d-m-Y',
'filter' => [
'class' => \Itguild\Tables\Filter\InputDateFilter::class
]
],
'updated_at' => function ($data) { 'updated_at' => function ($data) {
if (!$data){ if (!$data){
return null; return null;

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
@ -48,6 +49,10 @@ class EloquentDataProvider
$this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table;
$this->meta['params'] = $options['params'] ?? []; $this->meta['params'] = $options['params'] ?? [];
$this->meta['actions'] = $options['actions'] ?? []; $this->meta['actions'] = $options['actions'] ?? [];
$this->meta['fillable'] = $options['fillable'] ?? null;
$this->meta['searchPrefix'] = $options['searchPrefix'] ?? '/search';
$this->meta['searchParams'] = $options['searchParams'] ?? [];
$this->meta['showFiltersRow'] = $options['showFiltersRow'] ?? true;
$this->filters = $options['filters'] ?? []; $this->filters = $options['filters'] ?? [];
$this->createQuery(); $this->createQuery();
$this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray(), $this->filters,))->getJson(); $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray(), $this->filters,))->getJson();
@ -55,6 +60,18 @@ class EloquentDataProvider
public function createQuery(): void 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) { if ($this->currentPage > 1) {
$this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage); $this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage);
} else { } else {

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' => 'Роль'
]; ];
} }
} }