12 Commits
0.2 ... 0.4.6

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
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
850b0b315a fix JSON creator 2024-08-08 11:15:07 +03:00
cba0498e7d some fix 2024-08-07 15:40:01 +03:00
b4afddc7f7 add filters 2024-08-07 15:28:18 +03:00
50b642be1a Merge branch 'master' of https://git.itguild.info/ItGuild/eloquent_table 2024-08-07 15:27:33 +03:00
e84051ae21 add filters 2024-08-07 15:26:44 +03:00
7 changed files with 47 additions and 1989 deletions

3
.gitignore vendored
View File

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

View File

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

1974
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -4,6 +4,8 @@ namespace Itguild\EloquentTable;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use itguild\forms\debug\Debug;
class EloquentDataProvider
{
@ -19,6 +21,7 @@ class EloquentDataProvider
protected array $options = [];
protected array $meta = [];
protected array $filters = [];
protected string $jsonStr = '';
/**
@ -46,14 +49,28 @@ 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();
$this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson();
$this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray(), $this->filters,))->getJson();
}
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

@ -7,12 +7,13 @@ class JSONCreator
{
protected array $informationArray = [];
public function __construct(array $meta, array $data)
public function __construct(array $meta, array $data, array $filters = [])
{
$params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params'];
if ($meta) {
$this->informationArray = [
"meta" => $meta,
"filters" => $filters,
"data" => $data ?? []
];
}

View File

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