MicroFrameWork/kernel/modules/post/service/PostService.php

36 lines
919 B
PHP
Raw Permalink Normal View History

2024-07-25 16:15:18 +03:00
<?php
2024-09-06 16:53:20 +03:00
namespace kernel\modules\post\service;
2024-07-25 16:15:18 +03:00
use kernel\helpers\Debug;
2024-09-26 14:47:13 +03:00
use kernel\helpers\Slug;
2024-09-06 16:53:20 +03:00
use kernel\modules\post\models\Post;
2024-07-25 16:15:18 +03:00
use kernel\FormModel;
class PostService
{
public function create(FormModel $form_model): false|Post
{
$model = new Post();
2024-07-26 11:57:05 +03:00
$model->content = $form_model->getItem('content');
$model->user_id = $form_model->getItem('user_id');
2024-09-26 14:47:13 +03:00
$model->title = $form_model->getItem('title');
2024-10-01 16:00:14 +03:00
$model->slug = Slug::createSlug($form_model->getItem('title'), Post::class);
2024-07-25 16:15:18 +03:00
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, Post $post): false|Post
{
2024-07-26 11:57:05 +03:00
$post->content = $form_model->getItem('content');
$post->user_id = $form_model->getItem('user_id');
2024-07-25 16:15:18 +03:00
if ($post->save()){
return $post;
}
return false;
}
}