post crud fix
This commit is contained in:
@ -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) {
|
||||
|
@ -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',
|
||||
];
|
||||
}
|
||||
|
@ -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;
|
||||
|
16
app/tables/columns/PostEditActionColumn.php
Normal file
16
app/tables/columns/PostEditActionColumn.php
Normal 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> ";
|
||||
}
|
||||
}
|
@ -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> ";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user