search params

This commit is contained in:
Kavalar 2024-12-23 17:24:30 +03:00
parent 13b54a563d
commit 72f528e75d
4 changed files with 13 additions and 2046 deletions

3
.gitignore vendored
View File

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

2044
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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([

View File

@ -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 {