diff --git a/app/controllers/PostController.php b/app/controllers/PostController.php index 1b903e6..5837fdc 100644 --- a/app/controllers/PostController.php +++ b/app/controllers/PostController.php @@ -30,7 +30,7 @@ class PostController extends Controller $postForm = new CreatePostForm(); $postService = new PostService(); $postForm->load($_REQUEST); - if((new UserService)->check($_REQUEST['user_id'])) { + if(UserService::check($_REQUEST['user_id'])) { if ($postForm->validate()) { $post = $postService->create($postForm); if ($post) { diff --git a/app/models/forms/CreatePostForm.php b/app/models/forms/CreatePostForm.php index 3e5fbca..8eb195f 100644 --- a/app/models/forms/CreatePostForm.php +++ b/app/models/forms/CreatePostForm.php @@ -9,7 +9,7 @@ class CreatePostForm extends FormModel public function rules(): array { return [ - 'content' => 'required|min-str-len:1|max-str-len:2048', + 'content' => 'required|min-str-len:1', 'user_id' => 'required|min-str-len:1', ]; } diff --git a/app/services/UserService.php b/app/services/UserService.php index 854aaa5..0f0142e 100644 --- a/app/services/UserService.php +++ b/app/services/UserService.php @@ -34,8 +34,9 @@ class UserService return false; } - public function check(int $user_id): bool + public static function check(int $user_id): bool { + if (User::where(['id' => $user_id])->first()) { return true; diff --git a/app/tables/columns/PostEditActionColumn.php b/app/tables/columns/PostEditActionColumn.php new file mode 100644 index 0000000..264cc34 --- /dev/null +++ b/app/tables/columns/PostEditActionColumn.php @@ -0,0 +1,16 @@ +baseUrl . $this->prefix . $this->id; + return " Редактировать "; + } +} \ No newline at end of file diff --git a/app/tables/columns/UserEditActionColumn.php b/app/tables/columns/UserEditActionColumn.php index f0db24d..84ce168 100644 --- a/app/tables/columns/UserEditActionColumn.php +++ b/app/tables/columns/UserEditActionColumn.php @@ -11,7 +11,7 @@ class UserEditActionColumn extends ActionColumn public function fetch(): string { // $link = $this->baseUrl . $this->prefix . $this->id . $this->prefix . "update"; - $link = $this->baseUrl . $this->prefix . "update" . $this->prefix . $this->id; + $link = $this->baseUrl . $this->prefix . $this->id; return " Редактировать "; } } \ No newline at end of file diff --git a/kernel/IGTabel/JSONCreator.php b/kernel/IGTabel/JSONCreator.php index 4bcd5fe..4d96b6c 100644 --- a/kernel/IGTabel/JSONCreator.php +++ b/kernel/IGTabel/JSONCreator.php @@ -10,9 +10,8 @@ class JSONCreator public function __construct(array $meta, array $data) { - $params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params']; - if ($meta && $data) { + if ($meta) { $this->informationArray = [ "meta" => [ "columns" => $meta['columns'] ?? [], @@ -24,7 +23,7 @@ class JSONCreator "params" => $params ], - "data" => $data + "data" => $data ?? [] ]; } } diff --git a/views/admin/post/index.php b/views/admin/post/index.php index b5802fd..58409e2 100644 --- a/views/admin/post/index.php +++ b/views/admin/post/index.php @@ -18,13 +18,14 @@ $dataProvider = new ListJsonTableEloquentCollection($contents, [ 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/post", ]); + $table = new ListJsonTable($dataProvider->getJson()); $table->beforePrint(function (){ return PrimaryBtn::create("Создать", "/admin/post/create")->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); }); $table->addAction(UserViewActionColumn::class); -$table->addAction(UserEditActionColumn::class); +$table->addAction(\app\tables\columns\PostEditActionColumn::class); $table->addAction(UserDeleteActionColumn::class); $table->create(); $table->render(); \ No newline at end of file