igfs/app/services/PostService.php
2024-07-25 16:15:18 +03:00

32 lines
689 B
PHP

<?php
namespace app\services;
use app\models\Post;
use kernel\FormModel;
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');
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, Post $post): false|Post
{
$post->post = $form_model->getItem('post');
$post->username = $form_model->getItem('username');
if ($post->save()){
return $post;
}
return false;
}
}