HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/werkenbijanvil.komma.nl/app/Projects/Kms/ProjectController.php
<?php

namespace App\Projects\Kms;


use App\Projects\Models\ProjectTranslation;
use App\Projects\Models\Project;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Core\SectionController;
use Komma\KMS\Core\Tree\NestedSets\Nodes\TreeModelInterface;
use Komma\KMS\Sites\HasSiteInterface;

final class ProjectController extends SectionController
{
    protected string $slug = "projects";
    protected string $classModelName = Project::class;
    protected ?string $forTranslationModelName = ProjectTranslation::class;

    function __construct()
    {
        $section = new ProjectSection($this->slug);
        parent::__construct($section);
    }

    protected function save(Model $model, Collection $attributesByValueFrom = null): Model
    {
        /** @var AbstractTranslatableModel|HasSiteInterface|TreeModelInterface $model */
        if(!$model->exists) {
            $rootModel = $this->classModelName::allRoot()->first();
            $model->makeLastChildOf($rootModel);
        }
        $model = parent::save($model, $attributesByValueFrom);

        return $model;
    }
}