eloquent_table/index.php

102 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2024-08-06 13:11:24 +03:00
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Builder;
use Illuminate\Container\Container;
use Itguild\EloquentTable\EloquentDataProvider;
2024-08-06 16:27:37 +03:00
use Itguild\EloquentTable\ListEloquentTable;
use Itguild\EloquentTable\models\User;
2024-08-06 16:46:23 +03:00
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
2024-08-06 16:27:37 +03:00
use Itguild\Tables\ActionColumn\EditActionColumn;
2024-08-06 13:11:24 +03:00
use Itguild\Tables\ListJsonTable;
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();
2024-08-06 16:27:37 +03:00
try {
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'currentPage' => 1,
'perPage' => 3,
'params' => ["class" => "table table-bordered", "border" => "2"],
2024-08-29 13:15:41 +03:00
'baseUrl' => "/admin/user",
'filters' => ["email"]
2024-08-06 16:27:37 +03:00
]));
2024-08-07 12:23:49 +03:00
$table->columns([
2024-08-29 12:44:40 +03:00
'username' => [
'filter' => [
'class' => \Itguild\Tables\Filter\InputTextFilter::class
]
],
'created_at' => [
'format' => 'date:d-m-Y',
'filter' => [
'class' => \Itguild\Tables\Filter\InputDateFilter::class
]
],
2024-08-07 12:40:38 +03:00
'updated_at' => function ($data) {
if (!$data){
return null;
}
2024-08-07 12:23:49 +03:00
return (new DateTimeImmutable($data))->format("d-m-Y");
}
]);
2024-08-06 16:27:37 +03:00
$table->addAction(EditActionColumn::class);
$table->create();
$table->render();
} catch (Exception $e) {
}
2024-08-06 13:11:24 +03:00
2024-08-07 12:23:49 +03:00
try {
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel(User::find(1), [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
]));
2024-08-07 12:40:38 +03:00
$table->rows([
'created_at' => function ($data) {
if (!$data){
return null;
}
return (new DateTimeImmutable($data))->format("d-m-Y");
},
'updated_at' => function ($data) {
if (!$data){
return null;
}
return (new DateTimeImmutable($data))->format("d-m-Y");
}
]);
2024-08-07 12:23:49 +03:00
$table->create();
$table->render();
} catch (Exception $e) {
}
2024-08-06 16:46:23 +03:00