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/ste.komma.pro/app/Locations/Kms/LocationController.php
<?php

namespace App\Locations\Kms;

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

use App\Locations\Models\Location;
use App\Locations\Models\LocationTranslation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\SectionController;

final class LocationController extends SectionController
{
    protected $sortable = true;
    protected $slug = "locations";
    protected $classModelName = Location::class;

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

    public function save(Model $model, Collection $attributesByValueFrom = null): Model
    {
        if($model->lft === null) {
            /** @var Location $treeModel */
            $treeModel = Location::where('tree', '=', 1)
                ->where('lft', '=', 1)
                ->first();
            $model->makeLastChildOf($treeModel);
        }

        $model = parent::save($model, $attributesByValueFrom);

        return $model;
    }

}