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/SBogers95/rentman.io/app/Komma/PricingLabels/Kms/PricingLabelService.php
<?php

namespace App\Komma\PricingLabels\Kms;

use App\Komma\Kms\Core\Attributes\Models\SelectOptionInterface;
use App\Komma\Kms\Core\Sections\SectionService;
use App\Komma\PricingLabels\Models\PricingLabel;
use Illuminate\Support\Collection as BaseCollection;

class PricingLabelService extends SectionService
{
    protected $sortable = false;

    protected $orderByDisplayName = true;

    public function __construct()
    {
        $this->forModelName = PricingLabel::class;

        parent::__construct();
    }

    public function getOptionsForSelect($withRoot = false): BaseCollection
    {
        $selectOptions = collect();

        $products = PricingLabel::with('translation');
        $products = $products->get();

        foreach ($products as $product) {
            $name = $product->getDisplayName();

            if (empty($name)) {
                $name = __('kms/pricingproducts.entity').' '.$product->id;
            }

            /** @var SelectOptionInterface $selectOption */
            $selectOption = (\App::make(SelectOptionInterface::class))
                ->setContent($name)
                ->setHtmlContent($name)
                ->setValue($product->id);

            $selectOptions->push($selectOption);
        }

        return $selectOptions;
    }
}