39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
<?php
|
|
|
|
namespace kernel\app_modules\{slug}\service;
|
|
|
|
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;
|
|
}
|
|
} |