list eloquent table
This commit is contained in:
parent
22898f4c07
commit
a14f398532
40
index.php
40
index.php
@ -3,6 +3,9 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
|||||||
use Illuminate\Database\Schema\Builder;
|
use Illuminate\Database\Schema\Builder;
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
use Itguild\EloquentTable\EloquentDataProvider;
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
|
use Itguild\EloquentTable\models\User;
|
||||||
|
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||||
use Itguild\Tables\ListJsonTable;
|
use Itguild\Tables\ListJsonTable;
|
||||||
|
|
||||||
ini_set("display_errors", true);
|
ini_set("display_errors", true);
|
||||||
@ -34,29 +37,16 @@ $capsule->bootEloquent();
|
|||||||
|
|
||||||
$schema = $capsule->schema();
|
$schema = $capsule->schema();
|
||||||
|
|
||||||
//$dataProvider = new EloquentDataProvider(\Itguild\EloquentTable\models\User::class, [
|
try {
|
||||||
// 'currentPage' => 1,
|
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
|
||||||
// 'perPage' => 3,
|
'currentPage' => 1,
|
||||||
// 'params' => ["class" => "table table-bordered", "border" => "2"],
|
'perPage' => 3,
|
||||||
// 'baseUrl' => "/admin/user",
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
//]);
|
'baseUrl' => "/admin/user"
|
||||||
//$table = new ListJsonTable($dataProvider->getJson());
|
]));
|
||||||
//
|
$table->addAction(EditActionColumn::class);
|
||||||
//$table->addAction(\Itguild\Tables\ActionColumn\EditActionColumn::class);
|
$table->create();
|
||||||
//$table->create();
|
$table->render();
|
||||||
//$table->render();
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
$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->create();
|
|
||||||
$table->render();
|
|
@ -30,8 +30,6 @@ class EloquentDataProvider
|
|||||||
$this->queryBuilder = $source::query();
|
$this->queryBuilder = $source::query();
|
||||||
$model = new $source();
|
$model = new $source();
|
||||||
} elseif (is_object($source)) {
|
} elseif (is_object($source)) {
|
||||||
// echo "<pre>";
|
|
||||||
// print_r($source);die();
|
|
||||||
$this->queryBuilder = $source;
|
$this->queryBuilder = $source;
|
||||||
$model = $source->getModel();
|
$model = $source->getModel();
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,64 +3,20 @@
|
|||||||
namespace Itguild\EloquentTable;
|
namespace Itguild\EloquentTable;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Itguild\Tables\ListJsonTable;
|
use Itguild\Tables\ListJsonTable;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
|
||||||
class ListEloquentTable
|
class ListEloquentTable extends ListJsonTable
|
||||||
{
|
{
|
||||||
private array $options;
|
|
||||||
private string $model;
|
|
||||||
private ListJsonTable $table;
|
private ListJsonTable $table;
|
||||||
private EloquentDataProvider $dataProvider;
|
private EloquentDataProvider $dataProvider;
|
||||||
// public int $currentPage;
|
|
||||||
// public int $perPage;
|
|
||||||
// public array $params;
|
|
||||||
// public string $baseUrl;
|
|
||||||
// public array $actions;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(array $options)
|
#[NoReturn] public function __construct(EloquentDataProvider $dataProvider)
|
||||||
{
|
{
|
||||||
if (!isset ($options['model'])) {
|
$this->dataProvider = $dataProvider;
|
||||||
throw new Exception('Model option cannot be empty');
|
parent::__construct($this->dataProvider->getJson());
|
||||||
}
|
|
||||||
$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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user