File: D:/HostingSpaces/SBogers10/otium.komma.nl/app/Partners/Kms/PartnerController.php
<?php
namespace App\Partners\Kms;
use App\Partners\Models\PartnerTranslation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\SectionController;
use App\Partners\Models\Partner;
use Komma\KMS\Core\Tree\NestedSets\Nodes\TreeModelInterface;
final class PartnerController extends SectionController
{
protected string $slug = "partners";
protected string $classModelName = Partner::class;
protected ?string $forTranslationModelName = PartnerTranslation::class;
public function __construct()
{
$partnerSection = new PartnerSection($this->slug);
parent::__construct($partnerSection);
}
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;
}
}