Compare commits
8 Commits
850b0b315a
...
0.4.7
Author | SHA1 | Date | |
---|---|---|---|
7cdbff5ce9 | |||
a549c0ed75 | |||
72f528e75d | |||
13b54a563d | |||
a3b5f5fa0c | |||
708045664c | |||
d3cda0bd8f | |||
3bb6ae8b07 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
.env
|
.env
|
||||||
vendor
|
vendor
|
||||||
|
composer.lock
|
@ -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
1975
composer.lock
generated
File diff suppressed because it is too large
Load Diff
28
index.php
28
index.php
@ -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;
|
||||||
|
@ -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 {
|
||||||
|
@ -21,7 +21,8 @@ class User extends Model {
|
|||||||
'username' => 'Логин',
|
'username' => 'Логин',
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
'created_at' => 'Создан',
|
'created_at' => 'Создан',
|
||||||
'updated_at' => 'Обновлен'
|
'updated_at' => 'Обновлен',
|
||||||
|
'role' => 'Роль'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user