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