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/ste.komma.pro/app/Base/HasUspTrait.php
<?php


namespace App\Base;


use Illuminate\Support\Collection;

trait HasUspTrait
{
    private Collection $usp;
    protected int $amountOfUsp = 3;

    public function hasUsp(): bool
    {
        if(!isset($this->usp)) $this->makeUsp();
        return $this->usp->isNotEmpty();
    }

    public function getUsp(): Collection
    {
        if(!isset($this->usp)) $this->makeUsp();
        return $this->usp;
    }

    /**
     * Make the Usp because upon the amount of defined Usp
     * and the used (translation) model.
     */
    private function makeUsp(): void
    {
        $usp = collect();

        for($u = 1; $u <= $this->amountOfUsp; $u++) {

            $uspText = $this->{'usp_' . $u};
            if(empty($uspText)) continue;

            $usp->push($uspText);
        }

        $this->usp = $usp;
    }

}