File: D:/HostingSpaces/bomacon/bomacon.nl/app/Machines/Kms/MachineController.php
<?php
namespace App\Machines\Kms;
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
use App\Base\SectionControllerWithComponentAreas;
use App\Machines\Models\Machine;
use App\Machines\Models\MachineTranslation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
final class MachineController extends SectionControllerWithComponentAreas
{
protected $sortable = true;
protected $slug = 'machines';
protected $classModelName = Machine::class;
protected $forTranslationModelName = MachineTranslation::class;
public function __construct()
{
$section = new MachineSection($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;
}
}