diff --git a/index.php b/index.php index 17249ee..a21a960 100644 --- a/index.php +++ b/index.php @@ -34,14 +34,29 @@ $capsule->bootEloquent(); $schema = $capsule->schema(); -$dataProvider = new EloquentDataProvider(\Itguild\EloquentTable\models\User::class, [ +//$dataProvider = new EloquentDataProvider(\Itguild\EloquentTable\models\User::class, [ +// 'currentPage' => 1, +// 'perPage' => 3, +// 'params' => ["class" => "table table-bordered", "border" => "2"], +// 'baseUrl' => "/admin/user", +//]); +//$table = new ListJsonTable($dataProvider->getJson()); +// +//$table->addAction(\Itguild\Tables\ActionColumn\EditActionColumn::class); +//$table->create(); +//$table->render(); + +$table = new \Itguild\EloquentTable\ListEloquentTable([ + 'model' => \Itguild\EloquentTable\models\User::class, 'currentPage' => 1, 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/user", + 'actions' => [ + \Itguild\Tables\ActionColumn\ViewActionColumn::class, + \Itguild\Tables\ActionColumn\EditActionColumn::class + ] ]); -$table = new ListJsonTable($dataProvider->getJson()); -$table->addAction(\Itguild\Tables\ActionColumn\EditActionColumn::class); $table->create(); $table->render(); \ No newline at end of file diff --git a/src/EloquentDataProvider.php b/src/EloquentDataProvider.php index 75313fc..45c8729 100644 --- a/src/EloquentDataProvider.php +++ b/src/EloquentDataProvider.php @@ -30,8 +30,8 @@ class EloquentDataProvider $this->queryBuilder = $source::query(); $model = new $source(); } elseif (is_object($source)) { - echo "
";
- print_r($source);die();
+// echo "";
+// print_r($source);die();
$this->queryBuilder = $source;
$model = $source->getModel();
} else {
diff --git a/src/ListEloquentTable.php b/src/ListEloquentTable.php
new file mode 100644
index 0000000..cb07730
--- /dev/null
+++ b/src/ListEloquentTable.php
@@ -0,0 +1,66 @@
+model = $options['model'];
+// $this->currentPage = $options['currentPage'] ?? 1;
+// $this->perPage = $options['perPage'] ?? 5;
+// $this->params = $options['params'] ?? '';
+// $this->baseUrl = $options['base_url'] ?? '';
+ $this->options['currentPage'] = $options['currentPage'] ?? 1;
+ $this->options['perPage'] = $options['perPage'] ?? 5;
+ $this->options['params'] = $options['params'] ?? [];
+ $this->options['baseUrl'] = $options['baseUrl'] ?? '';
+ $this->options['actions'] = $options['actions'] ?? [];
+ $this->dataProvider = new EloquentDataProvider($this->model, $this->options);
+ $this->table = new ListJsonTable($this->dataProvider->getJson());
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function create(): void
+ {
+ if (isset($this->options['actions']))
+ {
+ $this->getActions();
+ }
+ $this->table->create();
+ }
+
+ private function getActions(): void
+ {
+ foreach ($this->options['actions'] as $action)
+ {
+ $this->table->addAction($action);
+ }
+ }
+
+ public function render(): void
+ {
+ $this->table->render();
+ }
+}
\ No newline at end of file