list eloquent table

This commit is contained in:
2024-08-06 16:27:37 +03:00
parent 22898f4c07
commit a14f398532
3 changed files with 20 additions and 76 deletions

View File

@ -30,8 +30,6 @@ class EloquentDataProvider
$this->queryBuilder = $source::query();
$model = new $source();
} elseif (is_object($source)) {
// echo "<pre>";
// print_r($source);die();
$this->queryBuilder = $source;
$model = $source->getModel();
} else {

View File

@ -3,64 +3,20 @@
namespace Itguild\EloquentTable;
use Exception;
use Itguild\Tables\ListJsonTable;
use JetBrains\PhpStorm\NoReturn;
class ListEloquentTable
class ListEloquentTable extends ListJsonTable
{
private array $options;
private string $model;
private ListJsonTable $table;
private EloquentDataProvider $dataProvider;
// public int $currentPage;
// public int $perPage;
// public array $params;
// public string $baseUrl;
// public array $actions;
/**
* @throws Exception
*/
public function __construct(array $options)
#[NoReturn] public function __construct(EloquentDataProvider $dataProvider)
{
if (!isset ($options['model'])) {
throw new Exception('Model option cannot be empty');
}
$this->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();
$this->dataProvider = $dataProvider;
parent::__construct($this->dataProvider->getJson());
}
}