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/otto-das.komma.pro/app/Utilities/Kms/UtilityController.php
<?php

namespace App\Utilities\Kms;

/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

use App\Base\SectionControllerWithComponentAreas;
use App\Utilities\Models\UtilityTranslation;
use App\Utilities\Models\Utility;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;

final class UtilityController extends SectionControllerWithComponentAreas
{
    protected $sortable = true;
    protected $slug = "utilities";
    protected $classModelName = Utility::class;
    protected $forTranslationModelName = UtilityTranslation::class;

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

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

        return $model;
    }
}