File: D:/HostingSpaces/Neopoints/momsecurity.be/app/QuestionCategories/Kms/QuestionCategoryController.php
<?php
namespace App\QuestionCategories\Kms;
use App\QuestionCategories\Models\QuestionCategory;
use App\QuestionCategories\Models\QuestionCategoryTranslation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\SectionController;
use Komma\KMS\Core\Tree\NestedSets\Nodes\TreeModelInterface;
final class QuestionCategoryController extends SectionController
{
protected string $slug = "question_categories";
protected string $classModelName = QuestionCategory::class;
protected ?string $forTranslationModelName = QuestionCategoryTranslation::class;
protected $sortable = true;
function __construct()
{
$questionCategorySection = new QuestionCategorySection($this->slug);
parent::__construct($questionCategorySection);
}
protected function save(Model $model, Collection $attributesByValueFrom = null): Model
{
/** @var TreeModelInterface $model */
if(!$model->exists) {
$rootModel = $this->classModelName::allRoot()->first();
$model->makeLastChildOf($rootModel);
}
$model = parent::save($model, $attributesByValueFrom);
return $model;
}
}