search params
This commit is contained in:
parent
13b54a563d
commit
72f528e75d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
.env
|
.env
|
||||||
vendor
|
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,
|
'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"]
|
'filters' => ["email"]
|
||||||
]));
|
]));
|
||||||
$table->columns([
|
$table->columns([
|
||||||
|
@ -49,6 +49,7 @@ class EloquentDataProvider
|
|||||||
$this->meta['params'] = $options['params'] ?? [];
|
$this->meta['params'] = $options['params'] ?? [];
|
||||||
$this->meta['actions'] = $options['actions'] ?? [];
|
$this->meta['actions'] = $options['actions'] ?? [];
|
||||||
$this->meta['searchPrefix'] = $options['searchPrefix'] ?? '/search';
|
$this->meta['searchPrefix'] = $options['searchPrefix'] ?? '/search';
|
||||||
|
$this->meta['searchParams'] = $options['searchParams'] ?? [];
|
||||||
$this->meta['showFiltersRow'] = $options['showFiltersRow'] ?? true;
|
$this->meta['showFiltersRow'] = $options['showFiltersRow'] ?? true;
|
||||||
$this->filters = $options['filters'] ?? [];
|
$this->filters = $options['filters'] ?? [];
|
||||||
$this->createQuery();
|
$this->createQuery();
|
||||||
@ -57,6 +58,13 @@ 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)){
|
||||||
|
$this->queryBuilder->where($name, $this->meta['searchParams'][$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user