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