From e84051ae212c1c590979ff7e1e51fd9ae210a0f6 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 7 Aug 2024 15:26:44 +0300 Subject: [PATCH] add filters --- src/EloquentDataProvider.php | 7 ++++--- src/JSONCreator.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EloquentDataProvider.php b/src/EloquentDataProvider.php index 8d1639f..853da54 100644 --- a/src/EloquentDataProvider.php +++ b/src/EloquentDataProvider.php @@ -4,6 +4,7 @@ namespace Itguild\EloquentTable; use Exception; use Illuminate\Database\Eloquent\Model; +use itguild\forms\debug\Debug; class EloquentDataProvider { @@ -19,6 +20,7 @@ class EloquentDataProvider protected array $options = []; protected array $meta = []; + protected array $filters = []; protected string $jsonStr = ''; /** @@ -46,10 +48,9 @@ class EloquentDataProvider $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; $this->meta['params'] = $options['params'] ?? []; $this->meta['actions'] = $options['actions'] ?? []; + $this->filters = $options['filters'] ?? []; $this->createQuery(); - - $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson(); - + $this->jsonStr = (new JSONCreator($this->meta, $this->filters, $this->getCollection()->toArray()))->getJson(); } public function createQuery(): void diff --git a/src/JSONCreator.php b/src/JSONCreator.php index f6ce444..e3ee133 100644 --- a/src/JSONCreator.php +++ b/src/JSONCreator.php @@ -7,12 +7,13 @@ class JSONCreator { protected array $informationArray = []; - public function __construct(array $meta, array $data) + public function __construct(array $meta, array $filters, array $data) { $params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params']; if ($meta) { $this->informationArray = [ "meta" => $meta, + "filters" => $filters, "data" => $data ?? [] ]; }