2024-12-12 11:58:55 +03:00
|
|
|
<?php
|
|
|
|
|
2024-12-12 15:04:45 +03:00
|
|
|
namespace kernel\app_modules\{slug}\services;
|
2024-12-12 11:58:55 +03:00
|
|
|
|
|
|
|
use kernel\helpers\Debug;
|
|
|
|
use kernel\app_modules\{slug}\models\{model};
|
|
|
|
use kernel\FormModel;
|
|
|
|
|
|
|
|
class {model}Service
|
|
|
|
{
|
|
|
|
public function create(FormModel $form_model): false|{model}
|
|
|
|
{
|
|
|
|
$model = new {model}();
|
|
|
|
// Пример заполнения:
|
|
|
|
// $model->content = $form_model->getItem('content');
|
|
|
|
// $model->user_id = $form_model->getItem('user_id');
|
|
|
|
// $model->title = $form_model->getItem('title');
|
|
|
|
// $model->slug = Slug::createSlug($form_model->getItem('title'), {model}::class); // Генерация уникального slug
|
|
|
|
|
|
|
|
if ($model->save()){
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(FormModel $form_model, {model} ${slug}): false|{model}
|
|
|
|
{
|
|
|
|
// Пример обновления:
|
|
|
|
// ${slug}->content = $form_model->getItem('content');
|
|
|
|
// ${slug}->user_id = $form_model->getItem('user_id');
|
|
|
|
|
|
|
|
if (${slug}->save()){
|
|
|
|
return ${slug};
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|