add view eloquent table
This commit is contained in:
parent
a14f398532
commit
59599f0344
12
index.php
12
index.php
@ -5,6 +5,8 @@ use Illuminate\Container\Container;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use Itguild\EloquentTable\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
|
||||
@ -50,3 +52,13 @@ try {
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
//try {
|
||||
// $table = new ViewEloquentTable(new ViewJsonTableEloquentModel(User::find(1), [
|
||||
// 'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
// 'baseUrl' => "/admin/user",
|
||||
// ]));
|
||||
// $table->create();
|
||||
// $table->render();
|
||||
//} catch (Exception $e) {
|
||||
//}
|
||||
|
||||
|
25
src/ViewEloquentTable.php
Normal file
25
src/ViewEloquentTable.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Itguild\EloquentTable;
|
||||
|
||||
use Exception;
|
||||
use Itguild\Tables\ViewJsonTable;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
class ViewEloquentTable extends ViewJsonTable
|
||||
{
|
||||
|
||||
private ViewJsonTable $table;
|
||||
private ViewJsonTableEloquentModel $dataProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
#[NoReturn] public function __construct(ViewJsonTableEloquentModel $dataProvider)
|
||||
{
|
||||
$this->dataProvider = $dataProvider;
|
||||
parent::__construct($this->dataProvider->getJson());
|
||||
}
|
||||
|
||||
}
|
45
view.php
Normal file
45
view.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Itguild\EloquentTable\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
|
||||
ini_set("display_errors", true);
|
||||
error_reporting(-1);
|
||||
|
||||
require_once __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
echo "<link rel='stylesheet' href='/vendor/twbs/bootstrap/dist/css/bootstrap.css'>";
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => $_ENV['DB_DRIVER'],
|
||||
'host' => $_ENV['DB_HOST'],
|
||||
'database' => $_ENV['DB_NAME'],
|
||||
'username' => $_ENV['DB_USER'],
|
||||
'password' => $_ENV['DB_PASSWORD'],
|
||||
'charset' => $_ENV['DB_CHARSET'],
|
||||
'collation' => $_ENV['DB_COLLATION'],
|
||||
'prefix' => $_ENV['DB_PREFIX'],
|
||||
]);
|
||||
// Setup the Eloquent ORM…
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
$capsule->bootEloquent();
|
||||
|
||||
$schema = $capsule->schema();
|
||||
|
||||
try {
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel(User::find(1), [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/user",
|
||||
]));
|
||||
$table->create();
|
||||
$table->render();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user