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;
}
}