user crud

This commit is contained in:
Kavalar 2024-07-23 15:22:33 +03:00
parent e07448550c
commit d75bc6defe
4 changed files with 104 additions and 61 deletions

View File

@ -7,9 +7,13 @@ use app\helpers\Debug;
use app\models\Question; use app\models\Question;
use app\models\User; use app\models\User;
use app\tables\columns\UserViewActionColumn; use app\tables\columns\UserViewActionColumn;
use Exception;
use http\Message;
use Itguild\Tables\ListJsonTable; use Itguild\Tables\ListJsonTable;
use Itguild\Tables\ViewJsonTable;
use kernel\Controller; use kernel\Controller;
use kernel\IGTabel\ListJsonTableEloquentCollection; use kernel\IGTabel\ListJsonTableEloquentCollection;
use kernel\IGTabel\ViewJsonTableEloquentModel;
use Twig\TwigFunction; use Twig\TwigFunction;
class UserController extends Controller{ class UserController extends Controller{
@ -54,17 +58,26 @@ class UserController extends Controller{
echo $this->twig->render('user_table.html.twig'); echo $this->twig->render('user_table.html.twig');
} }
/**
* @throws Exception
*/
public function actionView($id): void public function actionView($id): void
{ {
echo User::where('id', '=', $id)->get();
echo User::where('id', '=', $id)->first() . "<br><br>";
$user = User::find($id); $user = User::find($id);
echo $user->id . "<br>"; if (!$user){
echo $user->username . "<br>"; throw new Exception(message: "The user not found");
echo $user->email . "<br>"; }
echo $user->created_at . "<br>"; $this->twig->addFunction(new TwigFunction('table', function () use ($user){
echo $user->updated_at . "<br>"; $dataProvider = new ViewJsonTableEloquentModel($user, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
]);
$table = new ViewJsonTable($dataProvider->getJson());
$table->create();
$table->render();
}));
echo $this->twig->render('user_table.html.twig');
} }
public function actionUpdate(): void public function actionUpdate(): void

104
composer.lock generated
View File

@ -275,24 +275,24 @@
}, },
{ {
"name": "graham-campbell/result-type", "name": "graham-campbell/result-type",
"version": "v1.1.2", "version": "v1.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git", "url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862" "reference": "3ba905c11371512af9d9bdd27d99b782216b6945"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/fbd48bce38f73f8a4ec8583362e732e4095e5862", "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862", "reference": "3ba905c11371512af9d9bdd27d99b782216b6945",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"phpoption/phpoption": "^1.9.2" "phpoption/phpoption": "^1.9.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2" "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -321,7 +321,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues", "issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.2" "source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.3"
}, },
"funding": [ "funding": [
{ {
@ -333,20 +333,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-12T22:16:48+00:00" "time": "2024-07-20T21:45:45+00:00"
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478" "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/9bf68f03bbe05d38c9bd99bac8798c0de61f8478", "url": "https://api.github.com/repos/illuminate/collections/zipball/ba2cf689f7d75315f483334b4efc8c6af1d5159c",
"reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478", "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -388,11 +388,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-07-02T20:54:37+00:00" "time": "2024-07-15T21:44:45+00:00"
}, },
{ {
"name": "illuminate/conditionable", "name": "illuminate/conditionable",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/conditionable.git", "url": "https://github.com/illuminate/conditionable.git",
@ -438,7 +438,7 @@
}, },
{ {
"name": "illuminate/container", "name": "illuminate/container",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/container.git", "url": "https://github.com/illuminate/container.git",
@ -489,7 +489,7 @@
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
@ -537,16 +537,16 @@
}, },
{ {
"name": "illuminate/database", "name": "illuminate/database",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/database.git", "url": "https://github.com/illuminate/database.git",
"reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7" "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/database/zipball/9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7", "url": "https://api.github.com/repos/illuminate/database/zipball/cf816e7e0d08e2a75b233ad061eed85dd8b6b37f",
"reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7", "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -601,11 +601,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-07-08T15:08:27+00:00" "time": "2024-07-15T22:28:28+00:00"
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
@ -651,16 +651,16 @@
}, },
{ {
"name": "illuminate/support", "name": "illuminate/support",
"version": "v11.15.0", "version": "v11.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/support.git", "url": "https://github.com/illuminate/support.git",
"reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2" "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/b551f6cbecc607bcaf520eb3fc1933db9b1398f2", "url": "https://api.github.com/repos/illuminate/support/zipball/4fd85fffd9a4812386b6e10b2a18272ff9040dbe",
"reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2", "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -721,15 +721,15 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-07-08T14:46:56+00:00" "time": "2024-07-16T13:48:58+00:00"
}, },
{ {
"name": "itguild/tables", "name": "itguild/tables",
"version": "0.1.5", "version": "0.1.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.itguild.info/ItGuild/tables", "url": "https://git.itguild.info/ItGuild/tables",
"reference": "85c4a850b190e20944dc5ee5e888b6ecd342f82f" "reference": "48e6d645d97ace1eec258819da758f53db0b7d46"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -747,20 +747,20 @@
"email": "apuc06@mail.ru" "email": "apuc06@mail.ru"
} }
], ],
"time": "2024-07-16T10:26:29+00:00" "time": "2024-07-23T12:17:16+00:00"
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "3.6.0", "version": "3.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "39c8ef752db6865717cc3fba63970c16f057982c" "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/39c8ef752db6865717cc3fba63970c16f057982c", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cb4374784c87d0a0294e8513a52eb63c0aff3139",
"reference": "39c8ef752db6865717cc3fba63970c16f057982c", "reference": "cb4374784c87d0a0294e8513a52eb63c0aff3139",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -853,20 +853,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-06-20T15:52:59+00:00" "time": "2024-07-16T22:29:20+00:00"
}, },
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.9.2", "version": "1.9.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/schmittjoh/php-option.git", "url": "https://github.com/schmittjoh/php-option.git",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820" "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/80735db690fe4fc5c76dfa7f9b770634285fa820", "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/e3fac8b24f56113f7cb96af14958c0dd16330f54",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820", "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -874,13 +874,13 @@
}, },
"require-dev": { "require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2", "bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2" "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"bamarni-bin": { "bamarni-bin": {
"bin-links": true, "bin-links": true,
"forward-command": true "forward-command": false
}, },
"branch-alias": { "branch-alias": {
"dev-master": "1.9-dev" "dev-master": "1.9-dev"
@ -916,7 +916,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/schmittjoh/php-option/issues", "issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.9.2" "source": "https://github.com/schmittjoh/php-option/tree/1.9.3"
}, },
"funding": [ "funding": [
{ {
@ -928,7 +928,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-12T21:59:55+00:00" "time": "2024-07-20T21:41:07+00:00"
}, },
{ {
"name": "psr/clock", "name": "psr/clock",
@ -1841,23 +1841,23 @@
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
"version": "v5.6.0", "version": "v5.6.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/vlucas/phpdotenv.git", "url": "https://github.com/vlucas/phpdotenv.git",
"reference": "2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4" "reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4", "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/a59a13791077fe3d44f90e7133eb68e7d22eaff2",
"reference": "2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4", "reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-pcre": "*", "ext-pcre": "*",
"graham-campbell/result-type": "^1.1.2", "graham-campbell/result-type": "^1.1.3",
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"phpoption/phpoption": "^1.9.2", "phpoption/phpoption": "^1.9.3",
"symfony/polyfill-ctype": "^1.24", "symfony/polyfill-ctype": "^1.24",
"symfony/polyfill-mbstring": "^1.24", "symfony/polyfill-mbstring": "^1.24",
"symfony/polyfill-php80": "^1.24" "symfony/polyfill-php80": "^1.24"
@ -1874,7 +1874,7 @@
"extra": { "extra": {
"bamarni-bin": { "bamarni-bin": {
"bin-links": true, "bin-links": true,
"forward-command": true "forward-command": false
}, },
"branch-alias": { "branch-alias": {
"dev-master": "5.6-dev" "dev-master": "5.6-dev"
@ -1909,7 +1909,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/vlucas/phpdotenv/issues", "issues": "https://github.com/vlucas/phpdotenv/issues",
"source": "https://github.com/vlucas/phpdotenv/tree/v5.6.0" "source": "https://github.com/vlucas/phpdotenv/tree/v5.6.1"
}, },
"funding": [ "funding": [
{ {
@ -1921,7 +1921,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-12T22:43:29+00:00" "time": "2024-07-20T21:52:34+00:00"
}, },
{ {
"name": "voku/portable-ascii", "name": "voku/portable-ascii",

View File

@ -15,7 +15,8 @@ class JSONCreator
if ($meta && $data) { if ($meta && $data) {
$this->informationArray = [ $this->informationArray = [
"meta" => [ "meta" => [
"columns" => $meta['columns'], "columns" => $meta['columns'] ?? [],
"rows" => $meta['rows'] ?? [],
"perPage" => $meta['perPage'] ?? 10, "perPage" => $meta['perPage'] ?? 10,
"currentPage" => $meta['currentPage'] ?? 1, "currentPage" => $meta['currentPage'] ?? 1,
"baseUrl" => $meta['baseUrl'] ?? '', "baseUrl" => $meta['baseUrl'] ?? '',

View File

@ -0,0 +1,29 @@
<?php
namespace kernel\IGTabel;
use app\helpers\Debug;
use Illuminate\Database\Eloquent\Model;
class ViewJsonTableEloquentModel
{
private string|null $jsonStr;
private array $meta = [];
public function __construct(Model $model, array $params = [])
{
$this->meta['rows'] = $params['rows'] ?? $model->labels();
$this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table;
$this->meta['params'] = $params['params'] ?? [];
$this->meta['actions'] = $params['actions'] ?? [];
$this->jsonStr = (new JSONCreator($this->meta, $model->toArray()))->getJson();
}
public function getJson(): ?string
{
return $this->jsonStr;
}
}