fix post crud

This commit is contained in:
2024-07-26 11:57:05 +03:00
parent 25e585655c
commit f5f546ba95
10 changed files with 42 additions and 38 deletions

View File

@ -10,8 +10,8 @@ class PostService
public function create(FormModel $form_model): false|Post
{
$model = new Post();
$model->post = $form_model->getItem('post');
$model->username = $form_model->getItem('username');
$model->content = $form_model->getItem('content');
$model->user_id = $form_model->getItem('user_id');
if ($model->save()){
return $model;
}
@ -21,8 +21,8 @@ class PostService
public function update(FormModel $form_model, Post $post): false|Post
{
$post->post = $form_model->getItem('post');
$post->username = $form_model->getItem('username');
$post->content = $form_model->getItem('content');
$post->user_id = $form_model->getItem('user_id');
if ($post->save()){
return $post;
}

View File

@ -34,9 +34,9 @@ class UserService
return false;
}
public function check(string $username): bool
public function check(int $user_id): bool
{
if (User::where(['username' => $username])->first())
if (User::where(['id' => $user_id])->first())
{
return true;
}