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/reiskick.komma.nl/app/Hotels/Kms/HotelService.php
<?php


namespace App\Hotels\Kms;


use App\Hotels\Models\Hotel;
use Illuminate\Support\Str;
use Komma\KMS\Core\Attributes\Models\SelectOptionInterface;
use Komma\KMS\Core\ModelService;
use Komma\KMS\Core\Sections\SidebarListItem;

class HotelService extends ModelService
{

    public function __construct()
    {
        parent::__construct();
        $this->modelClassName = Hotel::class;
    }

    public function getComponentSelectOptions()
    {
        $models = $this->modelClassName::with('country', 'translation')
            ->where('lft', '!=', 1)
            ->get();

        $options = [];

        foreach ($models as $model) {

            $title = $model->getSidebarName() . ' | ' . $model->country->name;

            $selectOption = (app()->make(SelectOptionInterface::class))
                ->setContent($model->getSidebarName() . ' | ' . $model->country->name)
                ->setHtmlContent($model->getSidebarName() . ' | ' . $model->country->name)
                ->setValue($model->id);

            // Make sure there is always a unique key
            if(isset($sidebarList[Str::slug($title)])) $key = $title.$model->id;

            $options[Str::slug($title)] = $selectOption;
        }

        ksort($options);

        return $options;
    }

}