add Eloquent Tables
This commit is contained in:
@ -2,25 +2,44 @@
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $contents
|
||||
* @var int $page_number
|
||||
*/
|
||||
|
||||
use app\models\Post;
|
||||
use app\models\User;
|
||||
use app\tables\columns\PostDeleteActionColumn;
|
||||
use app\tables\columns\PostEditActionColumn;
|
||||
use app\tables\columns\PostViewActionColumn;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||
|
||||
$dataProvider = new ListJsonTableEloquentCollection($contents, [
|
||||
'model' => Post::class,
|
||||
'perPage' => 5,
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 3,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post",
|
||||
]);
|
||||
'baseUrl' => "/admin/post"
|
||||
]));
|
||||
$table->columns([
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = new ListJsonTable($dataProvider->getJson());
|
||||
$table->beforePrint(function (){
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'updated_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'user_id' => (function ($data) {
|
||||
return User::find($data)->username;
|
||||
})
|
||||
]);
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
});
|
||||
|
@ -3,22 +3,54 @@
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $content
|
||||
*/
|
||||
use Itguild\Tables\ViewJsonTable;
|
||||
|
||||
use app\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\IGTabel\btn\DangerBtn;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\btn\SuccessBtn;
|
||||
use kernel\IGTabel\ViewJsonTableEloquentModel;
|
||||
|
||||
$dataProvider = new ViewJsonTableEloquentModel($content, [
|
||||
//$dataProvider = new ViewJsonTableEloquentModel($content, [
|
||||
// 'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
// 'baseUrl' => "/admin/user",
|
||||
//]);
|
||||
//$table = new ViewJsonTable($dataProvider->getJson());
|
||||
//$table->beforeTable(function () use ($content) {
|
||||
// $btn = PrimaryBtn::create("Список", "/admin/post")->fetch();
|
||||
// $btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch();
|
||||
// $btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch();
|
||||
// return $btn;
|
||||
//});
|
||||
//$table->create();
|
||||
//$table->render();
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/user",
|
||||
]);
|
||||
$table = new ViewJsonTable($dataProvider->getJson());
|
||||
$table->beforeTable(function () use ($content) {
|
||||
'baseUrl' => "/admin/post",
|
||||
]));
|
||||
$table->beforePrint(function () use ($content) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/post")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$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");
|
||||
},
|
||||
'user_id' => (function ($data) {
|
||||
return User::find($data)->username;
|
||||
})
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
@ -8,28 +8,37 @@ use app\models\User;
|
||||
use app\tables\columns\UserDeleteActionColumn;
|
||||
use app\tables\columns\UserEditActionColumn;
|
||||
use app\tables\columns\UserViewActionColumn;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||
|
||||
|
||||
$dataProvider = new \kernel\IGTabel\EloquentDataProvider(User::where(['status' => 2]), [
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 3,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/user",
|
||||
'filters' => ['username', 'email'],
|
||||
]));
|
||||
$table->columns([
|
||||
'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");
|
||||
}
|
||||
]);
|
||||
$table = new ListJsonTable($dataProvider->getJson());
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
});
|
||||
$table->afterPrint(function ($meta) {
|
||||
$pagination = new \Itguild\Tables\Pagination($meta['totalWithFilters'], $meta['perPage'], $meta['currentPage'], $meta['baseUrl'] . "/page");
|
||||
$pagination->create();
|
||||
return $pagination->fetch();
|
||||
});
|
||||
$table->addAction(UserViewActionColumn::class);
|
||||
$table->addAction(UserEditActionColumn::class);
|
||||
$table->addAction(UserDeleteActionColumn::class);
|
||||
|
@ -3,22 +3,53 @@
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $user
|
||||
*/
|
||||
use Itguild\Tables\ViewJsonTable;
|
||||
|
||||
use app\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\IGTabel\btn\DangerBtn;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\btn\SuccessBtn;
|
||||
use kernel\IGTabel\ViewJsonTableEloquentModel;
|
||||
|
||||
$dataProvider = new ViewJsonTableEloquentModel($user, [
|
||||
//$dataProvider = new ViewJsonTableEloquentModel($user, [
|
||||
// 'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
// 'baseUrl' => "/admin/user",
|
||||
//]);
|
||||
//$table = new ViewJsonTable($dataProvider->getJson());
|
||||
//$table->beforeTable(function () use ($user) {
|
||||
// $btn = PrimaryBtn::create("Список", "/admin/user")->fetch();
|
||||
// $btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch();
|
||||
// $btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch();
|
||||
// return $btn;
|
||||
//});
|
||||
//$table->create();
|
||||
//$table->render();
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/user",
|
||||
]);
|
||||
$table = new ViewJsonTable($dataProvider->getJson());
|
||||
$table->beforeTable(function () use ($user) {
|
||||
]));
|
||||
$table->beforePrint(function () use ($user) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/user")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$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");
|
||||
}
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
Reference in New Issue
Block a user