post crud fix

This commit is contained in:
2024-07-26 12:42:44 +03:00
parent f5f546ba95
commit 2d8f945cad
7 changed files with 25 additions and 8 deletions

View File

@ -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) {

View File

@ -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',
];
}

View File

@ -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;

View File

@ -0,0 +1,16 @@
<?php
namespace app\tables\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostEditActionColumn extends ActionColumn
{
protected string $prefix = "/update/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
}
}

View File

@ -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 " <a href='$link' class='btn btn-success'>Редактировать</a> ";
}
}